dolibarr  9.0.0
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  *
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 // Load translation files required by the page
36 $langs->loadLangs(array('bills', 'banks', 'companies'));
37 
38 // Security check
39 $id=GETPOST("id",'int');
40 $action=GETPOST('action','aZ09');
41 $confirm=GETPOST('confirm');
42 if ($user->societe_id) $socid=$user->societe_id;
43 // TODO ajouter regle pour restreindre acces paiement
44 //$result = restrictedArea($user, 'facture', $id,'');
45 
46 $object = new PaymentSocialContribution($db);
47 if ($id > 0)
48 {
49  $result=$object->fetch($id);
50  if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
51 }
52 
53 
54 /*
55  * Actions
56  */
57 
58 // Delete payment
59 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer)
60 {
61  $db->begin();
62 
63  $result = $object->delete($user);
64  if ($result > 0)
65  {
66  $db->commit();
67  header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php?mode=sconly");
68  exit;
69  }
70  else
71  {
72  setEventMessages($object->error, $object->errors, 'errors');
73  $db->rollback();
74  }
75 }
76 
77 // Validate social contribution
78 /*
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 /*
119  * View
120  */
121 
122 llxHeader();
123 
124 $socialcontrib=new ChargeSociales($db);
125 
126 $form = new Form($db);
127 
128 $h=0;
129 
130 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
131 $head[$h][1] = $langs->trans("Card");
132 $hselected = $h;
133 $h++;
134 
135 /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
136 $head[$h][1] = $langs->trans("Info");
137 $h++;
138 */
139 
140 
141 dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
142 
143 /*
144  * Deletion confirmation of payment
145  */
146 if ($action == 'delete')
147 {
148  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
149 }
150 
151 /*
152  * Validation confirmation of payment
153  */
154 /*
155 if ($action == 'valide')
156 {
157  $facid = $_GET['facid'];
158  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
159 
160 }
161 */
162 
163 
164 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/sociales/payments.php">' . $langs->trans("BackToList") . '</a>';
165 
166 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
167 
168 
169 print '<div class="fichecenter">';
170 print '<div class="underbanner clearboth"></div>';
171 
172 print '<table class="border" width="100%">';
173 
174 // Ref
175 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
176 print '<td colspan="3">';
177 print $form->showrefnav($object,'id','',1,'rowid','id');
178 print '</td></tr>';*/
179 
180 // Date
181 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep,'day').'</td></tr>';
182 
183 // Mode
184 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
185 
186 // Numero
187 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_paiement.'</td></tr>';
188 
189 // Montant
190 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
191 
192 // Note
193 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
194 
195 // Bank account
196 if (! empty($conf->banque->enabled))
197 {
198  if ($object->bank_account)
199  {
200  $bankline=new AccountLine($db);
201  $bankline->fetch($object->bank_line);
202 
203  print '<tr>';
204  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
205  print '<td colspan="3">';
206  print $bankline->getNomUrl(1,0,'showall');
207  print '</td>';
208  print '</tr>';
209  }
210 }
211 
212 print '</table>';
213 
214 print '</div>';
215 
216 dol_fiche_end();
217 
218 
219 /*
220  * List of social contributions payed
221  */
222 
223 $disable_delete = 0;
224 $sql = 'SELECT f.rowid as scid, f.libelle, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
225 $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
226 $sql.= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
227 $sql.= ' AND f.entity = '.$conf->entity;
228 $sql.= ' AND pf.rowid = '.$object->id;
229 
230 dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
231 $resql=$db->query($sql);
232 if ($resql)
233 {
234  $num = $db->num_rows($resql);
235 
236  $i = 0;
237  $total = 0;
238  print '<br><table class="noborder" width="100%">';
239  print '<tr class="liste_titre">';
240  print '<td>'.$langs->trans('SocialContribution').'</td>';
241  print '<td>'.$langs->trans('Type').'</td>';
242  print '<td>'.$langs->trans('Label').'</td>';
243  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
244  print '<td align="center">'.$langs->trans('Status').'</td>';
245  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
246  print "</tr>\n";
247 
248  if ($num > 0)
249  {
250  while ($i < $num)
251  {
252  $objp = $db->fetch_object($resql);
253 
254  print '<tr class="oddeven">';
255  // Ref
256  print '<td>';
257  $socialcontrib->fetch($objp->scid);
258  print $socialcontrib->getNomUrl(1);
259  print "</td>\n";
260  // Type
261  print '<td>';
262  print $socialcontrib->type_libelle;
263  /*print $socialcontrib->type;*/
264  print "</td>\n";
265  // Label
266  print '<td>'.$objp->libelle.'</td>';
267  // Expected to pay
268  print '<td align="right">'.price($objp->sc_amount).'</td>';
269  // Status
270  print '<td align="center">'.$socialcontrib->getLibStatut(4,$objp->amount).'</td>';
271  // Amount payed
272  print '<td align="right">'.price($objp->amount).'</td>';
273  print "</tr>\n";
274  if ($objp->paye == 1) // If at least one invoice is paid, disable delete
275  {
276  $disable_delete = 1;
277  }
278  $total = $total + $objp->amount;
279  $i++;
280  }
281  }
282 
283 
284  print "</table>\n";
285  $db->free($resql);
286 }
287 else
288 {
289  dol_print_error($db);
290 }
291 
292 
293 
294 /*
295  * Boutons Actions
296  */
297 print '<div class="tabsAction">';
298 
299 /*
300 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
301 {
302  if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
303  {
304  if ($user->rights->facture->paiement)
305  {
306  print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
307  }
308  }
309 }
310 */
311 
312 if ($action == '')
313 {
314  if ($user->rights->tax->charges->supprimer)
315  {
316  if (! $disable_delete)
317  {
318  print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
319  }
320  else
321  {
322  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
323  }
324  }
325 }
326 
327 print '</div>';
328 
329 // End of page
330 llxFooter();
331 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:1053
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...
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:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
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).
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.