card.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/payment_vat/card.php
  23. * \ingroup facture
  24. * \brief Onglet payment of a social contribution
  25. * \remarks Fichier presque identique a fournisseur/paiement/card.php
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  33. if (isModEnabled("banque")) {
  34. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('bills', 'banks', 'companies'));
  38. // Security check
  39. $id = GETPOST("id", 'int');
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm');
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. // TODO ajouter regle pour restreindre acces paiement
  46. //$result = restrictedArea($user, 'facture', $id,'');
  47. $object = new PaymentVAT($db);
  48. if ($id > 0) {
  49. $result = $object->fetch($id);
  50. if (!$result) {
  51. dol_print_error($db, 'Failed to get payment id '.$id);
  52. }
  53. }
  54. /*
  55. * Actions
  56. */
  57. // Delete payment
  58. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
  59. $db->begin();
  60. $result = $object->delete($user);
  61. if ($result > 0) {
  62. $db->commit();
  63. header("Location: ".DOL_URL_ROOT."/compta/tva/payments.php?mode=tvaonly");
  64. exit;
  65. } else {
  66. setEventMessages($object->error, $object->errors, 'errors');
  67. $db->rollback();
  68. }
  69. }
  70. // Validate social contribution
  71. /*
  72. if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer)
  73. {
  74. $db->begin();
  75. $result=$object->valide();
  76. if ($result > 0)
  77. {
  78. $db->commit();
  79. $factures=array(); // TODO Get all id of invoices linked to this payment
  80. foreach($factures as $id)
  81. {
  82. $fac = new Facture($db);
  83. $fac->fetch($id);
  84. $outputlangs = $langs;
  85. if (!empty($_REQUEST['lang_id']))
  86. {
  87. $outputlangs = new Translate("",$conf);
  88. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  89. }
  90. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  91. $fac->generateDocument($fac->modelpdf, $outputlangs);
  92. }
  93. }
  94. header('Location: card.php?id='.$object->id);
  95. exit;
  96. }
  97. else
  98. {
  99. setEventMessages($object->error, $object->errors, 'errors');
  100. $db->rollback();
  101. }
  102. }
  103. */
  104. /*
  105. * View
  106. */
  107. llxHeader();
  108. $tva = new TVA($db);
  109. $form = new Form($db);
  110. $h = 0;
  111. $head[$h][0] = DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$id;
  112. $head[$h][1] = $langs->trans("VATPayment");
  113. $hselected = $h;
  114. $h++;
  115. /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
  116. $head[$h][1] = $langs->trans("Info");
  117. $h++;
  118. */
  119. print dol_get_fiche_head($head, $hselected, $langs->trans("VATPayment"), -1, 'payment');
  120. /*
  121. * Deletion confirmation of payment
  122. */
  123. if ($action == 'delete') {
  124. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
  125. }
  126. /*
  127. * Validation confirmation of payment
  128. */
  129. /*
  130. if ($action == 'valide')
  131. {
  132. $facid = $_GET['facid'];
  133. print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  134. }
  135. */
  136. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/payments.php">'.$langs->trans("BackToList").'</a>';
  137. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
  138. print '<div class="fichecenter">';
  139. print '<div class="underbanner clearboth"></div>';
  140. print '<table class="border centpercent">';
  141. // Date
  142. print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
  143. // Mode
  144. print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  145. // Numero
  146. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
  147. // Montant
  148. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  149. // Note
  150. print '<tr><td>'.$langs->trans('Note').'</td><td class="wordbreak sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
  151. // Bank account
  152. if (isModEnabled("banque")) {
  153. if ($object->bank_account) {
  154. $bankline = new AccountLine($db);
  155. $bankline->fetch($object->bank_line);
  156. print '<tr>';
  157. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  158. print '<td>';
  159. print $bankline->getNomUrl(1, 0, 'showall');
  160. print '</td>';
  161. print '</tr>';
  162. }
  163. }
  164. print '</table>';
  165. print '</div>';
  166. print dol_get_fiche_end();
  167. /*
  168. * List of social contributions payed
  169. */
  170. $disable_delete = 0;
  171. $sql = 'SELECT f.rowid as scid, f.label as label, f.paye, f.amount as tva_amount, pf.amount';
  172. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_vat as pf,'.MAIN_DB_PREFIX.'tva as f';
  173. $sql .= ' WHERE pf.fk_tva = f.rowid';
  174. $sql .= ' AND f.entity = '.$conf->entity;
  175. $sql .= ' AND pf.rowid = '.((int) $object->id);
  176. dol_syslog("compta/payment_vat/card.php", LOG_DEBUG);
  177. $resql = $db->query($sql);
  178. if ($resql) {
  179. $num = $db->num_rows($resql);
  180. $i = 0;
  181. $total = 0;
  182. print '<br><table class="noborder centpercent">';
  183. print '<tr class="liste_titre">';
  184. print '<td>'.$langs->trans('VATDeclaration').'</td>';
  185. //print '<td>'.$langs->trans('Type').'</td>';
  186. print '<td>'.$langs->trans('Label').'</td>';
  187. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  188. print '<td class="center">'.$langs->trans('Status').'</td>';
  189. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  190. print "</tr>\n";
  191. if ($num > 0) {
  192. while ($i < $num) {
  193. $objp = $db->fetch_object($resql);
  194. print '<tr class="oddeven">';
  195. // Ref
  196. print '<td>';
  197. $tva->fetch($objp->scid);
  198. print $tva->getNomUrl(1);
  199. print "</td>\n";
  200. // Type
  201. /* print '<td>';
  202. print $tva->type_label;4
  203. print "</td>\n";*/
  204. // Label
  205. print '<td>'.$objp->label.'</td>';
  206. // Expected to pay
  207. print '<td class="right"><span class="amount">'.price($objp->tva_amount).'</span></td>';
  208. // Status
  209. print '<td class="center">'.$tva->getLibStatut(4, $objp->amount).'</td>';
  210. // Amount payed
  211. print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
  212. print "</tr>\n";
  213. if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
  214. $disable_delete = 1;
  215. }
  216. $total = $total + $objp->amount;
  217. $i++;
  218. }
  219. }
  220. print "</table>\n";
  221. $db->free($resql);
  222. } else {
  223. dol_print_error($db);
  224. }
  225. /*
  226. * Boutons Actions
  227. */
  228. print '<div class="tabsAction">';
  229. /*
  230. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  231. {
  232. if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
  233. {
  234. if ($user->rights->facture->paiement)
  235. {
  236. print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  237. }
  238. }
  239. }
  240. */
  241. if ($action == '') {
  242. if ($user->rights->tax->charges->supprimer) {
  243. if (!$disable_delete) {
  244. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  245. } else {
  246. print dolGetButtonAction($langs->trans("CantRemovePaymentVATPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  247. }
  248. }
  249. }
  250. print '</div>';
  251. // End of page
  252. llxFooter();
  253. $db->close();