dolibarr  7.0.0-beta
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@capnetworks.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
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 (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34 
35 $langs->load('bills');
36 $langs->load('banks');
37 $langs->load('companies');
38 
39 // Security check
40 $id=GETPOST("id",'int');
41 $action=GETPOST('action','aZ09');
42 $confirm=GETPOST('confirm');
43 if ($user->societe_id) $socid=$user->societe_id;
44 // TODO ajouter regle pour restreindre acces paiement
45 //$result = restrictedArea($user, 'facture', $id,'');
46 
47 $object = new PaymentSocialContribution($db);
48 if ($id > 0)
49 {
50  $result=$object->fetch($id);
51  if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
52 }
53 
54 
55 /*
56  * Actions
57  */
58 
59 // Delete payment
60 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer)
61 {
62  $db->begin();
63 
64  $result = $object->delete($user);
65  if ($result > 0)
66  {
67  $db->commit();
68  header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php?mode=sconly");
69  exit;
70  }
71  else
72  {
73  setEventMessages($object->error, $object->errors, 'errors');
74  $db->rollback();
75  }
76 }
77 
78 // Create payment
79 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer)
80 {
81  $db->begin();
82 
83  $result=$object->valide();
84 
85  if ($result > 0)
86  {
87  $db->commit();
88 
89  $factures=array(); // TODO Get all id of invoices linked to this payment
90  foreach($factures as $id)
91  {
92  $fac = new Facture($db);
93  $fac->fetch($id);
94 
95  $outputlangs = $langs;
96  if (! empty($_REQUEST['lang_id']))
97  {
98  $outputlangs = new Translate("",$conf);
99  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
100  }
101  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
102  $fac->generateDocument($fac->modelpdf, $outputlangs);
103  }
104  }
105 
106  header('Location: card.php?id='.$object->id);
107  exit;
108  }
109  else
110  {
111  setEventMessages($object->error, $object->errors, 'errors');
112  $db->rollback();
113  }
114 }
115 
116 
117 /*
118  * View
119  */
120 
121 llxHeader();
122 
123 $socialcontrib=new ChargeSociales($db);
124 
125 $form = new Form($db);
126 
127 $h=0;
128 
129 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
130 $head[$h][1] = $langs->trans("Card");
131 $hselected = $h;
132 $h++;
133 
134 /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
135 $head[$h][1] = $langs->trans("Info");
136 $h++;
137 */
138 
139 
140 dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
141 
142 /*
143  * Deletion confirmation of payment
144  */
145 if ($action == 'delete')
146 {
147  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
148 
149 }
150 
151 /*
152  * Validation confirmation of payment
153  */
154 if ($action == 'valide')
155 {
156  $facid = $_GET['facid'];
157  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
158 
159 }
160 
161 
162 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/sociales/payments.php">' . $langs->trans("BackToList") . '</a>';
163 
164 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
165 
166 
167 print '<div class="fichecenter">';
168 print '<div class="underbanner clearboth"></div>';
169 
170 print '<table class="border" width="100%">';
171 
172 // Ref
173 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
174 print '<td colspan="3">';
175 print $form->showrefnav($object,'id','',1,'rowid','id');
176 print '</td></tr>';*/
177 
178 // Date
179 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep,'day').'</td></tr>';
180 
181 // Mode
182 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
183 
184 // Numero
185 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_paiement.'</td></tr>';
186 
187 // Montant
188 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
189 
190 // Note
191 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
192 
193 // Bank account
194 if (! empty($conf->banque->enabled))
195 {
196  if ($object->bank_account)
197  {
198  $bankline=new AccountLine($db);
199  $bankline->fetch($object->bank_line);
200 
201  print '<tr>';
202  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
203  print '<td colspan="3">';
204  print $bankline->getNomUrl(1,0,'showall');
205  print '</td>';
206  print '</tr>';
207  }
208 }
209 
210 print '</table>';
211 
212 print '</div>';
213 
214 dol_fiche_end();
215 
216 
217 /*
218  * List of social contributions payed
219  */
220 
221 $disable_delete = 0;
222 $sql = 'SELECT f.rowid as scid, f.libelle, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
223 $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
224 $sql.= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
225 $sql.= ' AND f.entity = '.$conf->entity;
226 $sql.= ' AND pf.rowid = '.$object->id;
227 
228 dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
229 $resql=$db->query($sql);
230 if ($resql)
231 {
232  $num = $db->num_rows($resql);
233 
234  $i = 0;
235  $total = 0;
236  print '<br><table class="noborder" width="100%">';
237  print '<tr class="liste_titre">';
238  print '<td>'.$langs->trans('SocialContribution').'</td>';
239  print '<td>'.$langs->trans('Type').'</td>';
240  print '<td>'.$langs->trans('Label').'</td>';
241  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
242  print '<td align="center">'.$langs->trans('Status').'</td>';
243  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
244  print "</tr>\n";
245 
246  if ($num > 0)
247  {
248  $var=True;
249 
250  while ($i < $num)
251  {
252  $objp = $db->fetch_object($resql);
253 
254 
255  print '<tr class="oddeven">';
256  // Ref
257  print '<td>';
258  $socialcontrib->fetch($objp->scid);
259  print $socialcontrib->getNomUrl(1);
260  print "</td>\n";
261  // Type
262  print '<td>';
263  print $socialcontrib->type_libelle;
264  /*print $socialcontrib->type;*/
265  print "</td>\n";
266  // Label
267  print '<td>'.$objp->libelle.'</td>';
268  // Expected to pay
269  print '<td align="right">'.price($objp->sc_amount).'</td>';
270  // Status
271  print '<td align="center">'.$socialcontrib->getLibStatut(4,$objp->amount).'</td>';
272  // Amount payed
273  print '<td align="right">'.price($objp->amount).'</td>';
274  print "</tr>\n";
275  if ($objp->paye == 1) // If at least one invoice is paid, disable delete
276  {
277  $disable_delete = 1;
278  }
279  $total = $total + $objp->amount;
280  $i++;
281  }
282  }
283 
284 
285  print "</table>\n";
286  $db->free($resql);
287 }
288 else
289 {
290  dol_print_error($db);
291 }
292 
293 
294 
295 /*
296  * Boutons Actions
297  */
298 print '<div class="tabsAction">';
299 
300 /*
301 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
302 {
303  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
304  {
305  if ($user->rights->facture->paiement)
306  {
307  print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
308  }
309  }
310 }
311 */
312 
313 if ($action == '')
314 {
315  if ($user->rights->tax->charges->supprimer)
316  {
317  if (! $disable_delete)
318  {
319  print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
320  }
321  else
322  {
323  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
324  }
325  }
326 }
327 
328 print '</div>';
329 
330 
331 
332 llxFooter();
333 
334 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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.
Class to manage payments of social contributions.
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage invoices.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...