card.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 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', '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."facture_fourn_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. $facturefournisseur_static = new FactureFournisseur($db);
  85. $formaccounting = new FormAccounting($db);
  86. if (!empty($id)) {
  87. $sql = "SELECT f.ref as ref, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
  88. $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,";
  89. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  90. $sql .= " ppe.accountancy_code_buy as code_buy,";
  91. } else {
  92. $sql .= " p.accountancy_code_buy as code_buy,";
  93. }
  94. $sql .= " aa.account_number, aa.label";
  95. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as l";
  96. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
  97. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  98. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  99. }
  100. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
  101. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = l.fk_facture_fourn ";
  102. $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
  103. $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
  104. dol_syslog("/accounting/supplier/card.php", LOG_DEBUG);
  105. $result = $db->query($sql);
  106. if ($result) {
  107. $num_lines = $db->num_rows($result);
  108. $i = 0;
  109. if ($num_lines) {
  110. $objp = $db->fetch_object($result);
  111. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  112. print '<input type="hidden" name="token" value="'.newToken().'">';
  113. print '<input type="hidden" name="action" value="ventil">';
  114. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
  115. print load_fiche_titre($langs->trans('SuppliersVentilation'), '', 'title_accountancy');
  116. print dol_get_fiche_head();
  117. print '<table class="border centpercent">';
  118. // ref invoice
  119. print '<tr><td>'.$langs->trans("BillsSuppliers").'</td>';
  120. $facturefournisseur_static->ref = $objp->ref;
  121. $facturefournisseur_static->id = $objp->facid;
  122. print '<td>'.$facturefournisseur_static->getNomUrl(1).'</td>';
  123. print '</tr>';
  124. print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
  125. print '<td>'.stripslashes(nl2br($objp->description)).'</td></tr>';
  126. print '<tr><td width="20%">'.$langs->trans("ProductLabel").'</td>';
  127. print '<td>'.dol_trunc($objp->product_label, 24).'</td>';
  128. print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
  129. print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  130. print '</td></tr>';
  131. print '</table>';
  132. print dol_get_fiche_end();
  133. print '<div class="center">';
  134. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  135. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  136. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  137. print '</div>';
  138. print '</form>';
  139. } else {
  140. print "Error";
  141. }
  142. } else {
  143. print "Error";
  144. }
  145. } else {
  146. print "Error ID incorrect";
  147. }
  148. // End of page
  149. llxFooter();
  150. $db->close();