card.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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) 2022 Alexandre Spangaro <aspangaro@open-dsi.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_sc/card.php
  23. * \ingroup tax
  24. * \brief Tab with payment of a social contribution
  25. * \remarks File similar to fourn/paiement/card.php
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.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', 'aZ09');
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. $object = new PaymentSocialContribution($db);
  46. if ($id > 0) {
  47. $result = $object->fetch($id);
  48. if (!$result) {
  49. dol_print_error($db, 'Failed to get payment id '.$id);
  50. }
  51. }
  52. $result = restrictedArea($user, 'payment_sc', $object, '');
  53. /*
  54. * Actions
  55. */
  56. // Delete payment
  57. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('tax', 'charges', 'supprimer')) {
  58. $db->begin();
  59. $result = $object->delete($user);
  60. if ($result > 0) {
  61. $db->commit();
  62. header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php");
  63. exit;
  64. } else {
  65. setEventMessages($object->error, $object->errors, 'errors');
  66. $db->rollback();
  67. }
  68. }
  69. /*if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('tax', 'charges', 'creer')) {
  70. $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
  71. $res = $object->update_date($datepaye);
  72. if ($res === 0) {
  73. setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
  74. } else {
  75. setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
  76. }
  77. }*/
  78. /*
  79. * View
  80. */
  81. llxHeader();
  82. $socialcontrib = new ChargeSociales($db);
  83. $form = new Form($db);
  84. $h = 0;
  85. $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
  86. $head[$h][1] = $langs->trans("PaymentSocialContribution");
  87. $hselected = $h;
  88. $h++;
  89. /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
  90. $head[$h][1] = $langs->trans("Info");
  91. $h++;
  92. */
  93. print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
  94. /*
  95. * Deletion confirmation of payment
  96. */
  97. if ($action == 'delete') {
  98. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
  99. }
  100. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/payments.php">'.$langs->trans("BackToList").'</a>';
  101. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
  102. print '<div class="fichecenter">';
  103. print '<div class="underbanner clearboth"></div>';
  104. print '<table class="border centpercent">';
  105. // Date
  106. print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
  107. // Mode
  108. print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
  109. // Numero
  110. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
  111. // Amount
  112. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
  113. // Note
  114. print '<tr><td>'.$langs->trans('Note').'</td><td class="wordbreak sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
  115. // Bank account
  116. if (isModEnabled("banque")) {
  117. if ($object->bank_account) {
  118. $bankline = new AccountLine($db);
  119. $bankline->fetch($object->bank_line);
  120. print '<tr>';
  121. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  122. print '<td>';
  123. print $bankline->getNomUrl(1, 0, 'showall');
  124. print '</td>';
  125. print '</tr>';
  126. }
  127. }
  128. print '</table>';
  129. print '</div>';
  130. print dol_get_fiche_end();
  131. /*
  132. * List of social contributions paid
  133. */
  134. $disable_delete = 0;
  135. $sql = 'SELECT f.rowid as scid, f.libelle as label, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
  136. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
  137. $sql .= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
  138. $sql .= ' AND f.entity = '.$conf->entity;
  139. $sql .= ' AND pf.rowid = '.((int) $object->id);
  140. dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
  141. $resql = $db->query($sql);
  142. if ($resql) {
  143. $num = $db->num_rows($resql);
  144. $i = 0;
  145. $total = 0;
  146. print '<br><table class="noborder centpercent">';
  147. print '<tr class="liste_titre">';
  148. print '<td>'.$langs->trans('SocialContribution').'</td>';
  149. print '<td>'.$langs->trans('Type').'</td>';
  150. print '<td>'.$langs->trans('Label').'</td>';
  151. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  152. print '<td class="center">'.$langs->trans('Status').'</td>';
  153. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  154. print "</tr>\n";
  155. if ($num > 0) {
  156. while ($i < $num) {
  157. $objp = $db->fetch_object($resql);
  158. print '<tr class="oddeven">';
  159. // Ref
  160. print '<td>';
  161. $socialcontrib->fetch($objp->scid);
  162. print $socialcontrib->getNomUrl(1);
  163. print "</td>\n";
  164. // Type
  165. print '<td>';
  166. print $socialcontrib->type_label;
  167. /*print $socialcontrib->type;*/
  168. print "</td>\n";
  169. // Label
  170. print '<td>'.$objp->label.'</td>';
  171. // Expected to pay
  172. print '<td class="right"><span class="amount">'.price($objp->sc_amount).'</span></td>';
  173. // Status
  174. print '<td class="center">'.$socialcontrib->getLibStatut(4, $objp->amount).'</td>';
  175. // Amount paid
  176. print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
  177. print "</tr>\n";
  178. if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
  179. $disable_delete = 1;
  180. }
  181. $total = $total + $objp->amount;
  182. $i++;
  183. }
  184. }
  185. print "</table>\n";
  186. $db->free($resql);
  187. } else {
  188. dol_print_error($db);
  189. }
  190. /*
  191. * Actions Buttons
  192. */
  193. print '<div class="tabsAction">';
  194. /*
  195. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  196. {
  197. if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
  198. {
  199. if ($user->rights->facture->paiement)
  200. {
  201. print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  202. }
  203. }
  204. }
  205. */
  206. if ($action == '') {
  207. if ($user->rights->tax->charges->supprimer) {
  208. if (!$disable_delete) {
  209. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  210. } else {
  211. print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  212. }
  213. }
  214. }
  215. print '</div>';
  216. // End of page
  217. llxFooter();
  218. $db->close();