card.php 5.1 KB

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