card.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/accountancy/customer/card.php
  21. * \ingroup Accountancy (Double entries)
  22. * \brief Card customer ventilation
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("bills", "accountancy"));
  29. $action = GETPOST('action', 'aZ09');
  30. $cancel = GETPOST('cancel', 'alpha');
  31. $backtopage = GETPOST('backtopage', 'alpha');
  32. $codeventil = GETPOST('codeventil', 'int');
  33. $id = GETPOST('id', 'int');
  34. // Security check
  35. if (!isModEnabled('accounting')) {
  36. accessforbidden();
  37. }
  38. if ($user->socid > 0) {
  39. accessforbidden();
  40. }
  41. if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
  42. accessforbidden();
  43. }
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
  48. if (!$cancel) {
  49. if ($codeventil < 0) {
  50. $codeventil = 0;
  51. }
  52. $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
  53. $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
  54. $sql .= " WHERE rowid = ".((int) $id);
  55. $resql = $db->query($sql);
  56. if (!$resql) {
  57. setEventMessages($db->lasterror(), null, 'errors');
  58. } else {
  59. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  60. if ($backtopage) {
  61. header("Location: ".$backtopage);
  62. exit();
  63. }
  64. }
  65. } else {
  66. header("Location: ./lines.php");
  67. exit();
  68. }
  69. }
  70. /*
  71. * View
  72. */
  73. llxHeader("", $langs->trans('FicheVentilation'));
  74. if ($cancel == $langs->trans("Cancel")) {
  75. $action = '';
  76. }
  77. /*
  78. * Create
  79. */
  80. $form = new Form($db);
  81. $facture_static = new Facture($db);
  82. $formaccounting = new FormAccounting($db);
  83. if (!empty($id)) {
  84. $sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
  85. $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
  86. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  87. $sql .= " ppe.accountancy_code_sell as code_sell,";
  88. } else {
  89. $sql .= " p.accountancy_code_sell as code_sell,";
  90. }
  91. $sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
  92. $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
  93. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
  94. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  95. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  96. }
  97. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
  98. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = l.fk_facture";
  99. $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
  100. $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
  101. dol_syslog("/accounting/customer/card.php", LOG_DEBUG);
  102. $result = $db->query($sql);
  103. if ($result) {
  104. $num_lines = $db->num_rows($result);
  105. $i = 0;
  106. if ($num_lines) {
  107. $objp = $db->fetch_object($result);
  108. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  109. print '<input type="hidden" name="token" value="'.newToken().'">';
  110. print '<input type="hidden" name="action" value="ventil">';
  111. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
  112. print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_accountancy');
  113. print dol_get_fiche_head();
  114. print '<table class="border centpercent">';
  115. // Ref facture
  116. print '<tr><td>'.$langs->trans("Invoice").'</td>';
  117. $facture_static->ref = $objp->ref;
  118. $facture_static->id = $objp->facid;
  119. print '<td>'.$facture_static->getNomUrl(1).'</td>';
  120. print '</tr>';
  121. print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
  122. print '<td>'.nl2br($objp->description).'</td></tr>';
  123. print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
  124. print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  125. print '</td></tr>';
  126. print '</table>';
  127. print dol_get_fiche_end();
  128. print '<div class="center">';
  129. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  130. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  131. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  132. print '</div>';
  133. print '</form>';
  134. } else {
  135. print "Error";
  136. }
  137. } else {
  138. print "Error";
  139. }
  140. } else {
  141. print "Error ID incorrect";
  142. }
  143. // End of page
  144. llxFooter();
  145. $db->close();