card.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/supplier/card.php
  26. * \ingroup Advanced accountancy
  27. * \brief Card supplier ventilation
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.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"));
  34. $action = GETPOST('action', 'alpha');
  35. $cancel = GETPOST('cancel', 'alpha');
  36. $backtopage = GETPOST('backtopage', 'alpha');
  37. $codeventil = GETPOST('codeventil');
  38. $id = GETPOST('id');
  39. // Security check
  40. if ($user->societe_id > 0)
  41. accessforbidden();
  42. /*
  43. * Actions
  44. */
  45. if ($action == 'ventil' && $user->rights->accounting->bind->write)
  46. {
  47. if (! $cancel)
  48. {
  49. if ($codeventil < 0) $codeventil = 0;
  50. $sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
  51. $sql .= " SET fk_code_ventilation = " . $codeventil;
  52. $sql .= " WHERE rowid = " . $id;
  53. $resql = $db->query($sql);
  54. if (! $resql) {
  55. setEventMessages($db->lasterror(), null, 'errors');
  56. }
  57. else
  58. {
  59. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  60. if ($backtopage)
  61. {
  62. header("Location: ".$backtopage);
  63. exit();
  64. }
  65. }
  66. } else {
  67. header("Location: ./lines.php");
  68. exit();
  69. }
  70. }
  71. /*
  72. * View
  73. */
  74. llxHeader("", $langs->trans('FicheVentilation'));
  75. if ($cancel == $langs->trans("Cancel")) {
  76. $action = '';
  77. }
  78. // Create
  79. $form = new Form($db);
  80. $facturefournisseur_static = new FactureFournisseur($db);
  81. $formaccounting = new FormAccounting($db);
  82. if (! empty($id)) {
  83. $sql = "SELECT f.ref as ref, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
  84. $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label";
  85. $sql .= ", aa.account_number, aa.label";
  86. $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as l";
  87. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  88. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
  89. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn ";
  90. $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id;
  91. $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
  92. dol_syslog("/accounting/supplier/card.php sql=" . $sql, LOG_DEBUG);
  93. $result = $db->query($sql);
  94. if ($result) {
  95. $num_lines = $db->num_rows($result);
  96. $i = 0;
  97. if ($num_lines) {
  98. $objp = $db->fetch_object($result);
  99. print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
  100. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  101. print '<input type="hidden" name="action" value="ventil">';
  102. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
  103. print load_fiche_titre($langs->trans('SuppliersVentilation'), '', 'title_setup');
  104. dol_fiche_head();
  105. print '<table class="border" width="100%">';
  106. // ref invoice
  107. print '<tr><td>' . $langs->trans("BillsSuppliers") . '</td>';
  108. $facturefournisseur_static->ref = $objp->ref;
  109. $facturefournisseur_static->id = $objp->facid;
  110. print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
  111. print '</tr>';
  112. print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
  113. print '<td>' . stripslashes(nl2br($objp->description)) . '</td></tr>';
  114. print '<tr><td width="20%">' . $langs->trans("ProductLabel") . '</td>';
  115. print '<td>' . dol_trunc($objp->product_label, 24) . '</td>';
  116. print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
  117. print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  118. print '</td></tr>';
  119. print '</table>';
  120. dol_fiche_end();
  121. print '<div class="center">';
  122. print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
  123. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  124. print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
  125. print '</div>';
  126. print '</form>';
  127. } else {
  128. print "Error";
  129. }
  130. } else {
  131. print "Error";
  132. }
  133. } else {
  134. print "Error ID incorrect";
  135. }
  136. // End of page
  137. llxFooter();
  138. $db->close();