card.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. // Ref
  142. /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
  143. print '<td colspan="3">';
  144. print $form->showrefnav($object,'id','',1,'rowid','id');
  145. print '</td></tr>';*/
  146. // Date
  147. print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
  148. // Mode
  149. print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  150. // Numero
  151. print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_paiement.'</td></tr>';
  152. // Montant
  153. print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  154. // Note
  155. print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
  156. // Bank account
  157. if (isModEnabled("banque")) {
  158. if ($object->bank_account) {
  159. $bankline = new AccountLine($db);
  160. $bankline->fetch($object->bank_line);
  161. print '<tr>';
  162. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  163. print '<td colspan="3">';
  164. print $bankline->getNomUrl(1, 0, 'showall');
  165. print '</td>';
  166. print '</tr>';
  167. }
  168. }
  169. print '</table>';
  170. print '</div>';
  171. print dol_get_fiche_end();
  172. /*
  173. * List of social contributions payed
  174. */
  175. $disable_delete = 0;
  176. $sql = 'SELECT f.rowid as scid, f.label as label, f.paye, f.amount as tva_amount, pf.amount';
  177. //$sql .= ', pc.libelle as sc_type';
  178. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_vat as pf,'.MAIN_DB_PREFIX.'tva as f';
  179. //$sql .= ', '.MAIN_DB_PREFIX.'c_chargesociales as pc';
  180. $sql .= ' WHERE pf.fk_tva = f.rowid';
  181. //$sql .= ' AND f.fk_type = pc.id';
  182. $sql .= ' AND f.entity = '.$conf->entity;
  183. $sql .= ' AND pf.rowid = '.((int) $object->id);
  184. dol_syslog("compta/payment_vat/card.php", LOG_DEBUG);
  185. $resql = $db->query($sql);
  186. if ($resql) {
  187. $num = $db->num_rows($resql);
  188. $i = 0;
  189. $total = 0;
  190. print '<br><table class="noborder centpercent">';
  191. print '<tr class="liste_titre">';
  192. print '<td>'.$langs->trans('VATDeclaration').'</td>';
  193. //print '<td>'.$langs->trans('Type').'</td>';
  194. print '<td>'.$langs->trans('Label').'</td>';
  195. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  196. print '<td class="center">'.$langs->trans('Status').'</td>';
  197. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  198. print "</tr>\n";
  199. if ($num > 0) {
  200. while ($i < $num) {
  201. $objp = $db->fetch_object($resql);
  202. print '<tr class="oddeven">';
  203. // Ref
  204. print '<td>';
  205. $tva->fetch($objp->scid);
  206. print $tva->getNomUrl(1);
  207. print "</td>\n";
  208. // Type
  209. /* print '<td>';
  210. print $tva->type_label;4
  211. print "</td>\n";*/
  212. // Label
  213. print '<td>'.$objp->label.'</td>';
  214. // Expected to pay
  215. print '<td class="right"><span class="amount">'.price($objp->tva_amount).'</span></td>';
  216. // Status
  217. print '<td class="center">'.$tva->getLibStatut(4, $objp->amount).'</td>';
  218. // Amount payed
  219. print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
  220. print "</tr>\n";
  221. if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
  222. $disable_delete = 1;
  223. }
  224. $total = $total + $objp->amount;
  225. $i++;
  226. }
  227. }
  228. print "</table>\n";
  229. $db->free($resql);
  230. } else {
  231. dol_print_error($db);
  232. }
  233. /*
  234. * Boutons Actions
  235. */
  236. print '<div class="tabsAction">';
  237. /*
  238. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  239. {
  240. if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
  241. {
  242. if ($user->rights->facture->paiement)
  243. {
  244. print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  245. }
  246. }
  247. }
  248. */
  249. if ($action == '') {
  250. if ($user->rights->tax->charges->supprimer) {
  251. if (!$disable_delete) {
  252. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  253. } else {
  254. print dolGetButtonAction($langs->trans("CantRemovePaymentVATPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  255. }
  256. }
  257. }
  258. print '</div>';
  259. // End of page
  260. llxFooter();
  261. $db->close();