card.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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-2015 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 Accounting Expert
  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.'/accountancy/class/html.formventilation.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->ventilation->dispatch) {
  41. if (! GETPOST('cancel', 'alpha'))
  42. {
  43. $sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
  44. $sql .= " SET fk_code_ventilation = " . $codeventil;
  45. $sql .= " WHERE rowid = " . $id;
  46. dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
  47. $resql = $db->query($sql);
  48. if (! $resql) {
  49. setEventMessage($db->lasterror(), 'errors');
  50. }
  51. } else {
  52. header("Location: ./lines.php");
  53. exit();
  54. }
  55. }
  56. /*
  57. * View
  58. */
  59. llxHeader("", "", "FicheVentilation");
  60. if ($cancel == $langs->trans("Cancel")) {
  61. $action = '';
  62. }
  63. /*
  64. * Create
  65. */
  66. $form = new Form($db);
  67. $facture_static = new Facture($db);
  68. $formventilation = new FormVentilation($db);
  69. if (! empty($id)) {
  70. $sql = "SELECT f.facnumber, f.rowid as facid, l.fk_product, l.description, l.price,";
  71. $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, p.accountancy_code_sell as code_sell,";
  72. $sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
  73. $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as l";
  74. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  75. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON l.fk_code_ventilation = aa.rowid";
  76. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = l.fk_facture";
  77. $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id;
  78. if (! empty($conf->multicompany->enabled)) {
  79. $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
  80. }
  81. dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
  82. $result = $db->query($sql);
  83. if ($result) {
  84. $num_lines = $db->num_rows($result);
  85. $i = 0;
  86. if ($num_lines) {
  87. $objp = $db->fetch_object($result);
  88. print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
  89. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  90. print '<input type="hidden" name="action" value="ventil">';
  91. print_fiche_titre($langs->trans('CustomersVentilation'),'','title_setup');
  92. dol_fiche_head();
  93. print '<table class="border" width="100%">';
  94. // Ref facture
  95. print '<tr><td>' . $langs->trans("Invoice") . '</td>';
  96. $facture_static->ref = $objp->facnumber;
  97. $facture_static->id = $objp->facid;
  98. print '<td>' . $facture_static->getNomUrl(1) . '</td>';
  99. print '</tr>';
  100. print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
  101. print '<td>' . nl2br($objp->description) . '</td></tr>';
  102. print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
  103. print $formventilation->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  104. print '</td></tr>';
  105. print '</table>';
  106. dol_fiche_end();
  107. print '<div class="center">';
  108. print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
  109. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  110. print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
  111. print '</div>';
  112. print '</form>';
  113. } else {
  114. print "Error";
  115. }
  116. } else {
  117. print "Error";
  118. }
  119. } else {
  120. print "Error ID incorrect";
  121. }
  122. llxFooter();
  123. $db->close();