PageRenderTime 85ms CodeModel.GetById 14ms app.highlight 63ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/don/card.php

https://github.com/atm-maximep/dolibarr
PHP | 763 lines | 540 code | 135 blank | 88 comment | 115 complexity | 5470adcfd34af2e0fcc0f9b5eebf2b63 MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2015	Laurent Destailleur		<eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2012	Regis Houssin			<regis.houssin@capnetworks.com>
  5 * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
  6 * Copyright (C) 2015       Alexandre Spangaro	  	<alexandre.spangaro@gmail.com>
  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 <http://www.gnu.org/licenses/>.
 20 */
 21
 22/**
 23 *  \file       htdocs/don/card.php
 24 *  \ingroup    donations
 25 *  \brief      Page of donation card
 26 */
 27
 28require '../main.inc.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
 33require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
 34require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
 35require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 36if (! empty($conf->projet->enabled))
 37{
 38	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
 39}
 40require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 41
 42$langs->load("companies");
 43$langs->load("donations");
 44$langs->load("bills");
 45
 46$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
 47$action=GETPOST('action','alpha');
 48$cancel=GETPOST('cancel');
 49$amount=GETPOST('amount');
 50$donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 51
 52$object = new Don($db);
 53$extrafields = new ExtraFields($db);
 54
 55// Security check
 56$result = restrictedArea($user, 'don', $id);
 57
 58// fetch optionals attributes and labels
 59$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
 60
 61// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 62$hookmanager->initHooks(array('doncard','globalcard'));
 63
 64/*
 65 * Actions
 66 */
 67
 68$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
 69if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 70
 71if ($action == 'update')
 72{
 73	if (! empty($cancel))
 74	{
 75		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
 76		exit;
 77	}
 78
 79	$error=0;
 80
 81    if (empty($donation_date))
 82    {
 83	    setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
 84        $action = "create";
 85        $error++;
 86    }
 87
 88	if (empty($amount))
 89	{
 90		setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
 91		$action = "create";
 92		$error++;
 93	}
 94
 95	if (! $error)
 96	{
 97		$object->fetch($id);
 98
 99		$object->firstname   = GETPOST("firstname");
100		$object->lastname    = GETPOST("lastname");
101		$object->societe     = GETPOST("societe");
102		$object->address     = GETPOST("address");
103		$object->amount      = price2num(GETPOST("amount"));
104		$object->town        = GETPOST("town");
105        $object->zip         = GETPOST("zipcode");
106        $object->country_id  = GETPOST('country_id', 'int');
107        $object->email       = GETPOST("email");
108		$object->date        = $donation_date;
109		$object->public      = GETPOST("public");
110		$object->fk_projet   = GETPOST("fk_projet");
111		$object->note_private= GETPOST("note_private");
112		$object->note_public = GETPOST("note_public");
113
114		// Fill array 'array_options' with data from add form
115        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
116		if ($ret < 0) $error++;
117
118		if ($object->update($user) > 0)
119		{
120			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
121			exit;
122		}
123	}
124}
125
126if ($action == 'add')
127{
128	if (! empty($cancel))
129	{
130		header("Location: index.php");
131		exit;
132	}
133
134	$error=0;
135
136    if (empty($donation_date))
137    {
138	    setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
139        $action = "create";
140        $error++;
141    }
142
143	if (empty($amount))
144	{
145		setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
146		$action = "create";
147		$error++;
148	}
149
150	if (! $error)
151	{
152		$object->firstname   = GETPOST("firstname");
153		$object->lastname    = GETPOST("lastname");
154		$object->societe     = GETPOST("societe");
155		$object->address     = GETPOST("address");
156		$object->amount      = price2num(GETPOST("amount"));
157        $object->zip         = GETPOST("zipcode");
158        $object->town        = GETPOST("town");
159        $object->country_id  = GETPOST('country_id', 'int');
160		$object->email       = GETPOST("email");
161		$object->date        = $donation_date;
162		$object->note_private= GETPOST("note_private");
163		$object->note_public = GETPOST("note_public");
164		$object->public      = GETPOST("public");
165		$object->fk_projet   = GETPOST("fk_projet");
166
167		// Fill array 'array_options' with data from add form
168        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
169		if ($ret < 0) $error++;
170
171		if ($object->create($user) > 0)
172		{
173			header("Location: index.php");
174			exit;
175		}
176		else
177		{
178			setEventMessages($object->error, $object->errors, 'errors');
179		}
180	}
181}
182if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer)
183{
184    $object->fetch($id);
185    $result=$object->delete($user);
186    if ($result > 0)
187    {
188        header("Location: index.php");
189        exit;
190    }
191    else
192    {
193        dol_syslog($object->error,LOG_DEBUG);
194        setEventMessage($object->error,'errors');
195        setEventMessage($object->errors,'errors');
196    }
197}
198if ($action == 'valid_promesse')
199{
200	if ($object->valid_promesse($id, $user->id) >= 0)
201	{
202		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
203		exit;
204	}
205    else {
206	    setEventMessage($object->error, 'errors');
207    }
208}
209if ($action == 'set_cancel')
210{
211    if ($object->set_cancel($id) >= 0)
212    {
213        header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
214        exit;
215    }
216    else {
217	    setEventMessage($object->error, 'errors');
218    }
219}
220if ($action == 'set_paid')
221{
222	if ($object->set_paid($id, $modepayment) >= 0)
223	{
224		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
225		exit;
226	}
227    else {
228	    setEventMessage($object->error, 'errors');
229    }
230}
231
232/*
233 * Build doc
234 */
235
236if ($action == 'builddoc')
237{
238	$object = new Don($db);
239	$result=$object->fetch($id);
240
241	// Save last template used to generate document
242	if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
243
244	// Define output language
245	$outputlangs = $langs;
246	$newlang='';
247	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
248	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
249	if (! empty($newlang))
250	{
251		$outputlangs = new Translate("",$conf);
252		$outputlangs->setDefaultLang($newlang);
253	}
254	$result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs);
255	if ($result <= 0)
256	{
257		dol_print_error($db,$result);
258		exit;
259	}
260}
261
262
263/*
264 * View
265 */
266
267llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
268
269$form=new Form($db);
270$formfile = new FormFile($db);
271$formcompany = new FormCompany($db);
272
273
274if ($action == 'create')
275{
276	print_fiche_titre($langs->trans("AddDonation"));
277
278	print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
279	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
280	print '<input type="hidden" name="action" value="add">';
281
282	dol_fiche_head('');
283
284	print '<table class="border" width="100%">';
285	print '<tbody>';
286
287    $nbrows=11;
288    if (! empty($conf->projet->enabled)) $nbrows++;
289
290    // Date
291	print '<tr><td class="fieldrequired" width="25%">'.$langs->trans("Date").'</td><td>';
292	$form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
293	print '</td>';
294
295    // Amount
296    print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" value="'.GETPOST("amount").'" size="10"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
297
298	print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
299	print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
300	print "</td></tr>\n";
301
302	print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.GETPOST("societe").'" size="40"></td></tr>';
303	print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.GETPOST("lastname").'" size="40"></td></tr>';
304	print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" value="'.GETPOST("firstname").'" size="40"></td></tr>';
305	print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
306	print '<textarea name="address" wrap="soft" cols="40" rows="3">'.GETPOST("address").'</textarea></td></tr>';
307
308    // Zip / Town
309    print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
310	print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
311    print ' ';
312    print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
313    print '</tr>';
314
315	// Country
316    print '<tr><td width="25%"><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
317    print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id);
318    if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
319    print '</td></tr>';
320
321	print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.GETPOST("email").'" size="40"></td></tr>';
322
323	// Public note
324	print '<tr>';
325	print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
326	print '<td valign="top" colspan="2">';
327
328    $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
329	print $doleditor->Create(1);
330	print '</td></tr>';
331
332	// Private note
333	if (empty($user->societe_id)) {
334		print '<tr>';
335		print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
336		print '<td valign="top" colspan="2">';
337
338		$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
339		print $doleditor->Create(1);
340		print '</td></tr>';
341	}
342
343	if (! empty($conf->projet->enabled))
344    {
345
346    	$formproject=new FormProjets($db);
347
348        print "<tr><td>".$langs->trans("Project")."</td><td>";
349        $formproject->select_projects(-1, GETPOST("fk_projet"),'fk_projet', 0, 0, 1, 1);
350		print "</td></tr>\n";
351    }
352
353    // Other attributes
354    $parameters=array('colspan' => 3);
355    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
356    if (empty($reshook) && ! empty($extrafields->attribute_label))
357    {
358		print $object->showOptionals($extrafields,'edit',$parameters);
359    }
360
361    print '</tbody>';
362	print "</table>\n";
363
364	dol_fiche_end();
365
366	print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
367
368	print "</form>\n";
369}
370
371
372/* ************************************************************ */
373/*                                                              */
374/* Donation card in edit mode                                   */
375/*                                                              */
376/* ************************************************************ */
377
378if (! empty($id) && $action == 'edit')
379{
380	$result=$object->fetch($id);
381	if ($result < 0) {
382		dol_print_error($db,$object->error); exit;
383	}
384	$result=$object->fetch_optionals($object->id,$extralabels);
385	if ($result < 0) {
386		dol_print_error($db); exit;
387	}
388
389	$hselected='card';
390	$head = donation_prepare_head($object);
391
392	print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
393	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
394	print '<input type="hidden" name="action" value="update">';
395	print '<input type="hidden" name="rowid" value="'.$object->id.'">';
396	print '<input type="hidden" name="amount" value="'.$object->amount.'">';
397
398
399	dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
400
401	print '<table class="border" width="100%">';
402
403	// Ref
404	print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
405	print $object->getNomUrl();
406	print '</td>';
407	print '</tr>';
408
409    $nbrows=12;
410    if (! empty($conf->projet->enabled)) $nbrows++;
411
412	// Date
413	print "<tr>".'<td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td>';
414	$form->select_date($object->date,'','','','',"update");
415	print '</td>';
416
417	// Amount
418	if ($object->statut == 0)
419	{
420		print "<tr>".'<td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="amount" size="10" value="'.$object->amount.'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
421	}
422	else
423	{
424		print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
425		print price($object->amount,0,$langs,0,0,-1,$conf->currency);
426		print '</td></tr>';
427	}
428
429	print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
430	print $form->selectyesno("public",1,1);
431	print "</td>";
432	print "</tr>\n";
433
434	$langs->load("companies");
435	print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$object->societe.'"></td></tr>';
436	print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" size="40" value="'.$object->lastname.'"></td></tr>';
437	print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" size="40" value="'.$object->firstname.'"></td></tr>';
438	print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
439	print '<textarea name="address" wrap="soft" cols="40" rows="'.ROWS_3.'">'.$object->address.'</textarea></td></tr>';
440
441    // Zip / Town
442    print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
443	print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
444    print ' ';
445	print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
446	print '</tr>';
447
448	// Country
449	print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
450	print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id');
451	if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
452	print '</td></tr>';
453
454	print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" size="40" value="'.$object->email.'"></td></tr>';
455
456    print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
457
458    if ($object->modepaymentid) $selected = $object->modepaymentid;
459    else $selected = '';
460
461    $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
462    print "</td></tr>\n";
463
464	print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
465
466    // Project
467    if (! empty($conf->projet->enabled))
468    {
469    	$formproject=new FormProjets($db);
470
471        $langs->load('projects');
472        print '<tr><td>'.$langs->trans('Project').'</td><td>';
473		$formproject->select_projects(-1, $object->fk_projet,'fk_projet', 0, 0, 1, 1);
474        print '</td></tr>';
475    }
476
477    // Other attributes
478    $parameters=array('colspan' => ' colspan="2"');
479    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
480    if (empty($reshook) && ! empty($extrafields->attribute_label))
481    {
482      	print $object->showOptionals($extrafields,'edit');
483    }
484
485	print "</table>\n";
486
487	dol_fiche_end();
488
489	print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'"> &nbsp; &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
490
491	print "</form>\n";
492}
493
494
495
496/* ************************************************************ */
497/*                                                              */
498/* Donation card in view mode                                   */
499/*                                                              */
500/* ************************************************************ */
501if (! empty($id) && $action != 'edit')
502{
503	// Confirmation delete
504    if ($action == 'delete')
505    {
506        $text=$langs->trans("ConfirmDeleteADonation");
507        print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1);
508    }
509
510	$result=$object->fetch($id);
511	if ($result < 0) {
512		dol_print_error($db,$object->error); exit;
513	}
514	$result=$object->fetch_optionals($object->id,$extralabels);
515	if ($result < 0) {
516		dol_print_error($db); exit;
517	}
518
519	$hselected='card';
520
521	$head = donation_prepare_head($object);
522	dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
523
524	print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
525	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
526	print '<table class="border" width="100%">';
527
528	$linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
529
530    $nbrows=12;
531    if (! empty($conf->projet->enabled)) $nbrows++;
532
533	// Ref
534	print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
535	print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', '');
536	print '</td>';
537	print '</tr>';
538
539	// Date
540	print '<tr><td width="25%">'.$langs->trans("Date").'</td><td colspan="2">';
541	print dol_print_date($object->date,"day");
542	print "</td>";
543
544    print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
545	print price($object->amount,0,$langs,0,0,-1,$conf->currency);
546	print '</td></tr>';
547
548	print '<tr><td>'.$langs->trans("PublicDonation").'</td><td colspan="2">';
549	print yn($object->public);
550	print '</td></tr>';
551
552	print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
553	print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
554	print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
555	print '<tr><td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($object->address).'</td>';
556
557	$rowspan=6;
558	if (! empty($conf->projet->enabled)) $rowspan++;
559	print '<td rowspan="'.$rowspan.'" valign="top">';
560
561	/*
562	 * Payments
563	 */
564	$sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,";
565	$sql.= "c.code as type_code,c.libelle as paiement_type";
566	$sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p";
567	$sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
568	$sql.= ", ".MAIN_DB_PREFIX."don as d";
569	$sql.= " WHERE d.rowid = '".$id."'";
570	$sql.= " AND p.fk_donation = d.rowid";
571	$sql.= " AND d.entity = ".$conf->entity;
572	$sql.= " AND p.fk_typepayment = c.id";
573	$sql.= " ORDER BY dp";
574
575	//print $sql;
576	$resql = $db->query($sql);
577	if ($resql)
578	{
579		$num = $db->num_rows($resql);
580		$i = 0; $total = 0;
581		print '<table class="nobordernopadding" width="100%">';
582		print '<tr class="liste_titre">';
583		print '<td>'.$langs->trans("RefPayment").'</td>';
584		print '<td>'.$langs->trans("Date").'</td>';
585		print '<td>'.$langs->trans("Type").'</td>';
586   		print '<td align="right">'.$langs->trans("Amount").'</td>';
587   		print '<td>&nbsp;</td>';
588   		print '</tr>';
589
590		$var=True;
591		while ($i < $num)
592		{
593			$objp = $db->fetch_object($resql);
594			$var=!$var;
595			print "<tr ".$bc[$var]."><td>";
596			print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
597			print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
598		        $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type;
599                               print "<td>".$labeltype.' '.$object->num_paiement."</td>\n";
600			print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
601			print "</tr>";
602			$totalpaid += $objp->amount;
603			$i++;
604		}
605
606		if ($object->paid == 0)
607		{
608			print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaid)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
609			print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->amount)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
610
611			$remaintopay = $object->amount - $totalpaid;
612
613			print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
614			print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
615		}
616		print "</table>";
617		$db->free($resql);
618	}
619	else
620	{
621		dol_print_error($db);
622	}
623	print "</td>";
624
625	print "</tr>";
626
627	// Zip / Town
628	print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
629	print $object->zip.($object->zip && $object->town?' / ':'').$object->town.'</td></tr>';
630
631	// Country
632	print '<tr><td>'.$langs->trans('Country').'</td><td>';
633	if (! empty($object->country_code))
634	{
635		$img=picto_from_langcode($object->country_code);
636		print ($img?$img.' ':'');
637		print $object->country;
638	}
639	else
640	{
641		print $object->country_olddata;
642	}
643	print '</td></tr>';
644
645	// EMail
646	print "<tr>".'<td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email).'</td></tr>';
647
648	// Payment mode
649	print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
650	$form->form_modes_reglement(null, $object->modepaymentid,'none');
651	print "</td></tr>\n";
652
653	print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
654
655    // Project
656    if (! empty($conf->projet->enabled))
657    {
658        print '<tr>';
659		print '<td>'.$langs->trans("Project").'</td>';
660		print '<td>';
661		$object->fetch_projet();
662		print $object->project->getNomUrl(4);
663		print '</td>';
664		print '</tr>';
665    }
666
667    // Other attributes
668    $parameters=array('colspan' => ' colspan="2"');
669    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
670    if (empty($reshook) && ! empty($extrafields->attribute_label))
671    {
672       	print $object->showOptionals($extrafields);
673    }
674
675	print "</table>\n";
676	print "</form>\n";
677
678	print "</div>";
679
680	$remaintopay = $object->amount - $totalpaid;
681
682	/**
683	 * Actions buttons
684	 */
685	print '<div class="tabsAction">';
686
687	print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
688
689	if ($object->statut == 0)
690	{
691		print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
692	}
693
694    if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0)
695    {
696        print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
697    }
698
699	// Create payment
700	if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer)
701	{
702		if ($remaintopay == 0)
703		{
704			print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
705		}
706		else
707		{
708			print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/don/payment/payment.php?rowid=' . $object->id . '&amp;action=create">' . $langs->trans('DoPayment') . '</a></div>';
709		}
710	}
711
712	// Classify 'paid'
713	if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
714	{
715		print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
716	}
717
718	// Delete
719	if ($user->rights->don->supprimer)
720	{
721		if ($don->statut == -1 || $don->statut == 0)
722		{
723			print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$don->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
724		}
725		else
726		{
727			print '<div class="inline-block divButAction"><a class="butActionDelete butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
728		}
729	}
730	else
731	{
732		print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
733	}
734
735	print "</div>";
736
737
738	print '<table width="100%"><tr><td width="50%" valign="top">';
739
740	/*
741	 * Documents generes
742	 */
743	$filename=dol_sanitizeFileName($object->id);
744	$filedir=$conf->don->dir_output . '/' . get_exdir($filename,2,0,1,$object,'donation'). '/'. dol_sanitizeFileName($object->ref);
745	$urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id;
746	//            $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
747	//            $delallowed=$user->rights->facture->supprimer;
748	$genallowed=1;
749	$delallowed=0;
750
751	$var=true;
752
753	print '<br>';
754	$formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
755
756	print '</td><td>&nbsp;</td>';
757
758	print '</tr></table>';
759
760}
761
762llxFooter();
763$db->close();