dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
4  * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.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.'/core/class/html.formfile.class.php';
30 require DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
31 require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
32 require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
34 
35 $langs->load('bills');
36 $langs->load('banks');
37 $langs->load('companies');
38 $langs->load("suppliers");
39 
40 $id = GETPOST('id','int');
41 $action = GETPOST('action','alpha');
42 $confirm = GETPOST('confirm','alpha');
43 
44 $object = new PaiementFourn($db);
45 
46 // PDF
47 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
48 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
49 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
50 
51 /*
52  * Actions
53  */
54 
55 if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
56 {
57  $db->begin();
58 
59  $object->fetch($id);
60  $result = $object->update_note(GETPOST('note','none'));
61  if ($result > 0)
62  {
63  $db->commit();
64  $action='';
65  }
66  else
67  {
68  setEventMessages($object->error, $object->errors, 'errors');
69  $db->rollback();
70  }
71 }
72 
73 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
74 {
75  $db->begin();
76 
77  $object->fetch($id);
78  $result = $object->delete();
79  if ($result > 0)
80  {
81  $db->commit();
82  header('Location: '.DOL_URL_ROOT.'/fourn/facture/paiement.php');
83  exit;
84  }
85  else
86  {
87  setEventMessages($object->error, $object->errors, 'errors');
88  $db->rollback();
89  }
90 }
91 
92 if ($action == 'confirm_valide' && $confirm == 'yes' &&
93  ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->facture->creer))
94  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
95 )
96 {
97  $db->begin();
98 
99  $object->fetch($id);
100  if ($object->valide() >= 0)
101  {
102  $db->commit();
103  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
104  exit;
105  }
106  else
107  {
108  setEventMessages($object->error, $object->errors, 'errors');
109  $db->rollback();
110  }
111 }
112 
113 if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement']))
114 {
115  $object->fetch($id);
116  $res = $object->update_num($_POST['num_paiement']);
117  if ($res === 0)
118  {
119  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
120  }
121  else
122  {
123  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
124  }
125 }
126 
127 if ($action == 'setdatep' && ! empty($_POST['datepday']))
128 {
129  $object->fetch($id);
130  $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
131  $res = $object->update_date($datepaye);
132  if ($res === 0)
133  {
134  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
135  }
136  else
137  {
138  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
139  }
140 }
141 
142 // Build document
143 $upload_dir = $conf->fournisseur->payment->dir_output;
144 // TODO: get the appropriate permisson
145 $permissioncreate = true;
146 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
147 
148 
149 /*
150  * View
151  */
152 
153 llxHeader();
154 
155 $result=$object->fetch($id);
156 
157 $form = new Form($db);
158 $formfile = new FormFile($db);
159 
160 $head = payment_supplier_prepare_head($object);
161 
162 dol_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
163 
164 if ($result > 0)
165 {
166  /*
167  * Confirmation de la suppression du paiement
168  */
169  if ($action == 'delete')
170  {
171  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
172 
173  }
174 
175  /*
176  * Confirmation de la validation du paiement
177  */
178  if ($action == 'valide')
179  {
180  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
181 
182  }
183 
184  $linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/paiement.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
185 
186 
187  dol_banner_tab($object,'id',$linkback,1,'rowid','ref');
188 
189  print '<div class="fichecenter">';
190  print '<div class="underbanner clearboth"></div>';
191 
192  print '<table class="border" width="100%">';
193 
194  /*print '<tr>';
195  print '<td width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">';
196  print $form->showrefnav($object,'id','',1,'rowid','ref');
197  print '</td></tr>';*/
198 
199  // Date payment
200  print '<tr><td class="titlefield" colspan="2">'.$form->editfieldkey("Date",'datep',$object->date,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
201  print $form->editfieldval("Date",'datep',$object->date,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded'));
202  print '</td></tr>';
203 
204  // Payment mode
205  $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle;
206  print '<tr><td colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
207 
208  // Payment numero
209  print '<tr><td colspan="2">'.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
210  print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
211  print '</td></tr>';
212 
213  // Amount
214  print '<tr><td colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant,'',$langs,0,0,-1,$conf->currency).'</td></tr>';
215 
216  if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
217  {
218  print '<tr><td colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
219  }
220 
221  // Note
222  print '<tr><td colspan="2">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
223  print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->fournisseur->facture->creer,'textarea');
224  print '</td></tr>';
225 
226  $allow_delete = 1 ;
227  // Bank account
228  if (! empty($conf->banque->enabled))
229  {
230  if ($object->bank_account)
231  {
232  $bankline=new AccountLine($db);
233  $bankline->fetch($object->bank_line);
234  if ($bankline->rappro)
235  {
236  $allow_delete=0;
237  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
238  }
239 
240  print '<tr>';
241  print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>';
242  print '<td colspan="3">';
243  print $bankline->getNomUrl(1,0,'showconciliated');
244  print '</td>';
245  print '</tr>';
246 
247  print '<tr>';
248  print '<td colspan="2">'.$langs->trans('BankAccount').'</td>';
249  print '<td colspan="3">';
250  $accountstatic=new Account($db);
251  $accountstatic->fetch($bankline->fk_account);
252  print $accountstatic->getNomUrl(1);
253  print '</td>';
254  print '</tr>';
255  }
256  }
257 
258  print '</table>';
259 
260  print '</div>';
261 
262  print '<br>';
263 
267  $sql = 'SELECT f.rowid, f.ref, f.ref_supplier, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom as name, s.rowid as socid';
268  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
269  $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
270  $sql .= ' AND pf.fk_paiementfourn = '.$object->id;
271  $resql=$db->query($sql);
272  if ($resql)
273  {
274  $num = $db->num_rows($resql);
275 
276  $i = 0;
277  $total = 0;
278  print '<b>'.$langs->trans("Invoices").'</b><br>';
279  print '<table class="noborder" width="100%">';
280  print '<tr class="liste_titre">';
281  print '<td>'.$langs->trans('Ref').'</td>';
282  print '<td>'.$langs->trans('RefSupplier').'</td>';
283  print '<td>'.$langs->trans('Company').'</td>';
284  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
285  print '<td align="center">'.$langs->trans('Status').'</td>';
286  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
287  print "</tr>\n";
288 
289  if ($num > 0)
290  {
291  $var=True;
292 
293  $facturestatic=new FactureFournisseur($db);
294 
295  while ($i < $num)
296  {
297  $objp = $db->fetch_object($resql);
298 
299  $facturestatic->id=$objp->facid;
300  $facturestatic->ref=($objp->ref?$objp->ref:$objp->rowid);
301 
302  print '<tr class="oddeven">';
303  // Ref
304  print '<td>';
305  print $facturestatic->getNomUrl(1);
306  print "</td>\n";
307  // Ref supplier
308  print '<td>'.$objp->ref_supplier."</td>\n";
309  // Third party
310  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->name.'</a></td>';
311  // Expected to pay
312  print '<td align="right">'.price($objp->total_ttc).'</td>';
313  // Status
314  print '<td align="center">'.$facturestatic->LibStatut($objp->paye,$objp->fk_statut,2,1).'</td>';
315  // Payed
316  print '<td align="right">'.price($objp->amount).'</td>';
317  print "</tr>\n";
318  if ($objp->paye == 1)
319  {
320  $allow_delete = 0;
321  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
322  }
323  $total = $total + $objp->amount;
324  $i++;
325  }
326  }
327 
328 
329  print "</table>\n";
330  $db->free($resql);
331  }
332  else
333  {
334  dol_print_error($db);
335  }
336 
337  print '</div>';
338 
339 
340  /*
341  * Boutons Actions
342  */
343 
344  print '<div class="tabsAction">';
345  if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
346  {
347  if ($user->societe_id == 0 && $object->statut == 0 && $action == '')
348  {
349  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->facture->creer))
350  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
351  {
352  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
353 
354  }
355  }
356  }
357  if ($user->societe_id == 0 && $action == '')
358  {
359  if ($user->rights->fournisseur->facture->supprimer)
360  {
361  if ($allow_delete)
362  {
363  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
364  }
365  else
366  {
367  print '<a class="butActionRefused" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
368  }
369  }
370  }
371  print '</div>';
372 
373 
374  print '<div class="fichecenter"><div class="fichehalfleft">';
375 
376  // Documents generes
377 
378  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
380  if (is_array($modellist))
381  {
382  $ref=dol_sanitizeFileName($object->ref);
383  $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
384  $urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id;
385  $genallowed=$user->rights->fournisseur->facture->lire;
386  $delallowed=$user->rights->fournisseur->facture->creer;
387  $modelpdf=(! empty($object->modelpdf)?$object->modelpdf:(empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)?'':$conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
388 
389  print $formfile->showdocuments('supplier_payment',$ref,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,40,0,'','','',$societe->default_lang);
390  $somethingshown=$formfile->numoffiles;
391  }
392 
393  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
394  //print '<br>';
395 
396  // List of actions on element
397  /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
398  $formactions=new FormActions($db);
399  $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
400  */
401 
402  print '</div></div></div>';
403 }
404 else
405 {
406  $langs->load("errors");
407  print $langs->trans("ErrorRecordNotFound");
408 }
409 
410 dol_fiche_end();
411 
412 llxFooter();
413 
414 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
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 suppliers invoices.
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage bank accounts.
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_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to offer components to list and upload files.
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...
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 payments for supplier invoices.