card.php 4.6 KB

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