dolibarr  16.0.5
card.php
Go to the documentation of this file.
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 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
34 if (isModEnabled('banque')) {
35  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 }
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('bills', 'banks', 'companies'));
40 
41 // Security check
42 $id = GETPOST("id", 'int');
43 $action = GETPOST('action', 'aZ09');
44 $confirm = GETPOST('confirm', 'aZ09');
45 if ($user->socid) {
46  $socid = $user->socid;
47 }
48 // TODO ajouter regle pour restreindre acces paiement
49 //$result = restrictedArea($user, 'facture', $id,'');
50 
51 $object = new PaymentSocialContribution($db);
52 if ($id > 0) {
53  $result = $object->fetch($id);
54  if (!$result) {
55  dol_print_error($db, 'Failed to get payment id '.$id);
56  }
57 }
58 
59 
60 /*
61  * Actions
62  */
63 
64 // Delete payment
65 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
66  $db->begin();
67 
68  $result = $object->delete($user);
69  if ($result > 0) {
70  $db->commit();
71  header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php");
72  exit;
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  $db->rollback();
76  }
77 }
78 
79 
80 /*
81  * View
82  */
83 
84 llxHeader();
85 
86 $socialcontrib = new ChargeSociales($db);
87 
88 $form = new Form($db);
89 
90 $h = 0;
91 
92 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
93 $head[$h][1] = $langs->trans("PaymentSocialContribution");
94 $hselected = $h;
95 $h++;
96 
97 /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
98 $head[$h][1] = $langs->trans("Info");
99 $h++;
100 */
101 
102 
103 print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
104 
105 /*
106  * Deletion confirmation of payment
107  */
108 if ($action == 'delete') {
109  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
110 }
111 
112 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/payments.php">'.$langs->trans("BackToList").'</a>';
113 
114 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
115 
116 
117 print '<div class="fichecenter">';
118 print '<div class="underbanner clearboth"></div>';
119 
120 print '<table class="border centpercent">';
121 
122 // Ref
123 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
124 print '<td colspan="3">';
125 print $form->showrefnav($object,'id','',1,'rowid','id');
126 print '</td></tr>';*/
127 
128 // Date
129 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
130 
131 // Mode
132 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
133 
134 // Numero
135 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
136 
137 // Amount
138 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
139 
140 // Note
141 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
142 
143 // Bank account
144 if (isModEnabled('banque')) {
145  if ($object->bank_account) {
146  $bankline = new AccountLine($db);
147  $bankline->fetch($object->bank_line);
148 
149  print '<tr>';
150  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
151  print '<td colspan="3">';
152  print $bankline->getNomUrl(1, 0, 'showall');
153  print '</td>';
154  print '</tr>';
155  }
156 }
157 
158 print '</table>';
159 
160 print '</div>';
161 
162 print dol_get_fiche_end();
163 
164 
165 /*
166  * List of social contributions paid
167  */
168 
169 $disable_delete = 0;
170 $sql = 'SELECT f.rowid as scid, f.libelle as label, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
171 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
172 $sql .= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
173 $sql .= ' AND f.entity = '.$conf->entity;
174 $sql .= ' AND pf.rowid = '.((int) $object->id);
175 
176 dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
177 $resql = $db->query($sql);
178 if ($resql) {
179  $num = $db->num_rows($resql);
180 
181  $i = 0;
182  $total = 0;
183  print '<br><table class="noborder centpercent">';
184  print '<tr class="liste_titre">';
185  print '<td>'.$langs->trans('SocialContribution').'</td>';
186  print '<td>'.$langs->trans('Type').'</td>';
187  print '<td>'.$langs->trans('Label').'</td>';
188  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
189  print '<td class="center">'.$langs->trans('Status').'</td>';
190  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
191  print "</tr>\n";
192 
193  if ($num > 0) {
194  while ($i < $num) {
195  $objp = $db->fetch_object($resql);
196 
197  print '<tr class="oddeven">';
198  // Ref
199  print '<td>';
200  $socialcontrib->fetch($objp->scid);
201  print $socialcontrib->getNomUrl(1);
202  print "</td>\n";
203  // Type
204  print '<td>';
205  print $socialcontrib->type_label;
206  /*print $socialcontrib->type;*/
207  print "</td>\n";
208  // Label
209  print '<td>'.$objp->label.'</td>';
210  // Expected to pay
211  print '<td class="right"><span class="amount">'.price($objp->sc_amount).'</span></td>';
212  // Status
213  print '<td class="center">'.$socialcontrib->getLibStatut(4, $objp->amount).'</td>';
214  // Amount paid
215  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
216  print "</tr>\n";
217  if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
218  $disable_delete = 1;
219  }
220  $total = $total + $objp->amount;
221  $i++;
222  }
223  }
224 
225 
226  print "</table>\n";
227  $db->free($resql);
228 } else {
229  dol_print_error($db);
230 }
231 
232 
233 
234 /*
235  * Actions Buttons
236  */
237 print '<div class="tabsAction">';
238 
239 /*
240 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
241 {
242  if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
243  {
244  if ($user->rights->facture->paiement)
245  {
246  print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
247  }
248  }
249 }
250 */
251 
252 if ($action == '') {
253  if ($user->rights->tax->charges->supprimer) {
254  if (!$disable_delete) {
255  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.GETPOST('id', 'int').'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
256  } else {
257  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
258  }
259  }
260 }
261 
262 print '</div>';
263 
264 // End of page
265 llxFooter();
266 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
ChargeSociales
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Definition: chargesociales.class.php:34
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
PaymentSocialContribution
Class to manage payments of social contributions.
Definition: paymentsocialcontribution.class.php:33
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59