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