dolibarr/htdocs/don/card.php

740 lines
26 KiB
PHP
Raw Normal View History

<?php
2012-07-11 10:14:56 +02:00
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
2013-04-09 17:18:07 +02:00
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
2015-03-16 06:29:15 +01:00
* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
2002-12-19 19:55:38 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2002-12-19 19:55:38 +01:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2002-12-19 19:55:38 +01:00
*/
2005-08-11 22:28:11 +02:00
/**
2015-03-25 22:37:14 +01:00
* \file htdocs/don/card.php
2015-03-22 08:20:19 +01:00
* \ingroup donations
* \brief Page of donation card
2008-11-14 12:56:47 +01:00
*/
2015-03-20 06:36:48 +01:00
require '../main.inc.php';
2015-03-22 08:20:19 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
2015-03-25 22:37:14 +01:00
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
2015-03-21 06:21:34 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
2015-03-18 06:29:10 +01:00
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
}
2015-03-16 06:29:15 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2002-12-19 19:55:38 +01:00
$langs->load("companies");
$langs->load("donations");
$langs->load("bills");
2012-07-11 10:14:56 +02:00
$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
$action=GETPOST('action','alpha');
$cancel=GETPOST('cancel');
$amount=GETPOST('amount');
2015-03-26 20:43:34 +01:00
$donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
2012-02-01 14:20:22 +01:00
2015-03-16 06:29:15 +01:00
$object = new Don($db);
2015-03-21 06:21:34 +01:00
$extrafields = new ExtraFields($db);
2012-02-01 14:20:22 +01:00
// Security check
$result = restrictedArea($user, 'don', $id);
2015-03-26 20:43:34 +01:00
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('doncard','globalcard'));
/*
* Actions
*/
2015-03-26 20:43:34 +01:00
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2008-11-15 19:20:40 +01:00
2012-02-01 14:20:22 +01:00
if ($action == 'update')
2002-12-19 19:55:38 +01:00
{
2012-07-11 10:14:56 +02:00
if (! empty($cancel))
2010-04-05 03:25:44 +02:00
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
2010-04-05 03:25:44 +02:00
exit;
}
2010-02-13 17:28:03 +01:00
$error=0;
2011-06-12 17:47:10 +02:00
if (empty($donation_date))
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
2012-02-01 14:20:22 +01:00
$action = "create";
2011-06-12 17:47:10 +02:00
$error++;
}
2010-02-13 17:28:03 +01:00
2012-07-11 10:14:56 +02:00
if (empty($amount))
2008-11-15 19:20:40 +01:00
{
2014-11-23 17:42:06 +01:00
setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
2012-02-01 14:20:22 +01:00
$action = "create";
2011-06-12 17:47:10 +02:00
$error++;
2010-02-13 17:28:03 +01:00
}
2008-11-15 19:20:40 +01:00
2010-02-13 17:28:03 +01:00
if (! $error)
{
2015-03-16 06:29:15 +01:00
$object->fetch($id);
$object->firstname = GETPOST("firstname");
$object->lastname = GETPOST("lastname");
$object->societe = GETPOST("societe");
$object->address = GETPOST("address");
$object->amount = price2num(GETPOST("amount"));
$object->town = GETPOST("town");
$object->zip = GETPOST("zipcode");
$object->country_id = GETPOST('country_id', 'int');
$object->email = GETPOST("email");
$object->date = $donation_date;
$object->public = GETPOST("public");
$object->fk_projet = GETPOST("fk_projet");
2015-03-16 06:29:15 +01:00
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
2015-03-21 06:21:34 +01:00
// Fill array 'array_options' with data from add form
2015-03-25 22:37:14 +01:00
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
2015-03-21 06:21:34 +01:00
if ($ret < 0) $error++;
2015-03-16 06:29:15 +01:00
if ($object->update($user) > 0)
2008-11-15 19:20:40 +01:00
{
2015-03-16 06:29:15 +01:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
2008-11-15 19:20:40 +01:00
exit;
}
}
}
2012-02-01 14:20:22 +01:00
if ($action == 'add')
{
2012-07-11 10:14:56 +02:00
if (! empty($cancel))
2010-04-05 03:25:44 +02:00
{
2012-08-31 05:58:38 +02:00
header("Location: index.php");
2010-04-05 03:25:44 +02:00
exit;
}
2010-02-13 17:28:03 +01:00
$error=0;
2011-06-12 17:47:10 +02:00
if (empty($donation_date))
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors');
2012-07-11 10:14:56 +02:00
$action = "create";
2011-06-12 17:47:10 +02:00
$error++;
}
2010-02-13 17:28:03 +01:00
2012-07-11 10:14:56 +02:00
if (empty($amount))
2010-02-13 17:28:03 +01:00
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors');
2012-07-11 10:14:56 +02:00
$action = "create";
2011-06-12 17:47:10 +02:00
$error++;
2010-02-13 17:28:03 +01:00
}
2008-11-15 19:20:40 +01:00
2010-02-13 17:28:03 +01:00
if (! $error)
{
2015-03-16 06:29:15 +01:00
$object->firstname = GETPOST("firstname");
$object->lastname = GETPOST("lastname");
$object->societe = GETPOST("societe");
$object->address = GETPOST("address");
$object->amount = price2num(GETPOST("amount"));
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST('country_id', 'int');
$object->email = GETPOST("email");
$object->date = $donation_date;
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
$object->public = GETPOST("public");
$object->fk_projet = GETPOST("fk_projet");
2015-03-21 06:21:34 +01:00
// Fill array 'array_options' with data from add form
2015-03-25 22:37:14 +01:00
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
2015-03-21 06:21:34 +01:00
if ($ret < 0) $error++;
2015-03-16 06:29:15 +01:00
if ($object->create($user) > 0)
2008-11-15 19:20:40 +01:00
{
2012-08-31 05:58:38 +02:00
header("Location: index.php");
2008-11-15 19:20:40 +01:00
exit;
}
}
2002-12-27 22:54:03 +01:00
}
2015-03-26 20:43:34 +01:00
if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer)
2002-12-26 11:22:14 +01:00
{
2015-03-26 20:43:34 +01:00
$object->fetch($id);
$result=$object->delete($user);
if ($result > 0)
{
header("Location: index.php");
exit;
}
else
{
dol_syslog($object->error,LOG_DEBUG);
setEventMessage($object->error,'errors');
setEventMessage($object->errors,'errors');
}
2002-12-26 11:22:14 +01:00
}
2012-02-01 14:20:22 +01:00
if ($action == 'valid_promesse')
2002-12-19 19:55:38 +01:00
{
2015-03-16 06:29:15 +01:00
if ($object->valid_promesse($id, $user->id) >= 0)
2008-11-15 19:20:40 +01:00
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
2008-11-15 19:20:40 +01:00
exit;
}
else {
2015-03-16 06:29:15 +01:00
setEventMessage($object->error, 'errors');
}
2011-06-12 17:47:10 +02:00
}
2012-02-01 14:20:22 +01:00
if ($action == 'set_cancel')
2011-06-12 17:47:10 +02:00
{
2015-03-16 06:29:15 +01:00
if ($object->set_cancel($id) >= 0)
2011-06-12 17:47:10 +02:00
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
2011-06-12 17:47:10 +02:00
exit;
}
else {
2015-03-16 06:29:15 +01:00
setEventMessage($object->error, 'errors');
}
2002-12-19 19:55:38 +01:00
}
2012-02-01 14:20:22 +01:00
if ($action == 'set_paid')
2002-12-19 19:55:38 +01:00
{
2015-03-29 09:20:32 +02:00
if ($object->set_paid($id, $modepayment) >= 0)
2008-11-15 19:20:40 +01:00
{
2012-08-31 05:58:38 +02:00
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
2008-11-15 19:20:40 +01:00
exit;
}
else {
2015-03-16 06:29:15 +01:00
setEventMessage($object->error, 'errors');
}
2002-12-19 19:55:38 +01:00
}
/*
* Build doc
*/
2012-02-01 14:20:22 +01:00
if ($action == 'builddoc')
{
$object = new Don($db);
$object->fetch($id);
2008-11-14 12:56:47 +01:00
// Save last template used to generate document
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
2008-11-14 12:56:47 +01:00
// Define output language
2008-11-14 12:56:47 +01:00
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
2008-11-14 12:56:47 +01:00
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
2008-11-14 12:56:47 +01:00
}
$result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs);
2008-11-14 12:56:47 +01:00
if ($result <= 0)
{
dol_print_error($db,$result);
2008-11-14 12:56:47 +01:00
exit;
}
}
2002-12-19 19:55:38 +01:00
2008-11-14 12:56:47 +01:00
/*
* View
*/
2002-12-19 19:55:38 +01:00
llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones');
2002-12-19 19:55:38 +01:00
$form=new Form($db);
$formfile = new FormFile($db);
$formcompany = new FormCompany($db);
2002-12-26 11:22:14 +01:00
/* ************************************************************************** */
/* */
2015-03-18 05:07:32 +01:00
/* Donation card in create mode */
2002-12-26 11:22:14 +01:00
/* */
/* ************************************************************************** */
2012-02-01 14:20:22 +01:00
if ($action == 'create')
{
2009-01-15 02:14:03 +01:00
print_fiche_titre($langs->trans("AddDonation"));
2008-11-15 19:20:40 +01:00
2015-03-16 06:29:15 +01:00
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-11-15 19:20:40 +01:00
print '<table class="border" width="100%">';
print '<input type="hidden" name="action" value="add">';
2011-06-12 17:47:10 +02:00
$nbrows=11;
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled)) $nbrows++;
2011-06-12 17:47:10 +02:00
// Date
2015-03-16 06:29:15 +01:00
print '<tr><td class="fieldrequired" width="25%">'.$langs->trans("Date").'</td><td>';
$form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1);
2008-11-15 19:20:40 +01:00
print '</td>';
2011-06-12 17:47:10 +02:00
// Amount
2015-03-16 06:29:15 +01:00
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>';
2008-11-15 19:20:40 +01:00
print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1);
2008-11-15 19:20:40 +01:00
print "</td></tr>\n";
2015-03-16 06:29:15 +01:00
print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" value="'.GETPOST("societe").'" size="40"></td></tr>';
print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" value="'.GETPOST("lastname").'" size="40"></td></tr>';
print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" value="'.GETPOST("firstname").'" size="40"></td></tr>';
2008-11-15 19:20:40 +01:00
print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
2015-03-16 06:29:15 +01:00
print '<textarea name="address" wrap="soft" cols="40" rows="3">'.GETPOST("address").'</textarea></td></tr>';
2011-06-12 17:47:10 +02:00
// Zip / Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
2015-03-16 06:29:15 +01:00
print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
2011-06-12 17:47:10 +02:00
print ' ';
2015-03-16 06:29:15 +01:00
print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
2011-06-12 17:47:10 +02:00
print '</tr>';
2015-03-16 06:29:15 +01:00
// Country
print '<tr><td width="25%"><label for="selectcountry_id">'.$langs->trans('Country').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id);
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>';
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.GETPOST("email").'" size="40"></td></tr>';
// Public note
print '<tr>';
print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
print '<td valign="top" colspan="2">';
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
print '</td></tr>';
// Private note
if (empty($user->societe_id)) {
print '<tr>';
print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
print '<td valign="top" colspan="2">';
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
print '</td></tr>';
}
2011-06-12 17:47:10 +02:00
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled))
2011-06-12 17:47:10 +02:00
{
$formproject=new FormProjets($db);
2011-06-12 17:47:10 +02:00
print "<tr><td>".$langs->trans("Project")."</td><td>";
$formproject->select_projects(-1, GETPOST("fk_projet"),'fk_projet', 0, 1, 0, 1);
2015-03-18 06:29:10 +01:00
print "</td></tr>\n";
2011-06-12 17:47:10 +02:00
}
// Other attributes
2015-03-25 22:37:14 +01:00
$parameters=array('colspan' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields,'edit',$parameters);
}
2008-11-15 19:20:40 +01:00
print "</table>\n";
2014-11-25 20:13:43 +01:00
print '<br><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>';
2008-11-15 19:20:40 +01:00
print "</form>\n";
}
/* ************************************************************ */
/* */
2015-03-18 05:07:32 +01:00
/* Donation card in edit mode */
/* */
/* ************************************************************ */
2012-07-11 10:14:56 +02:00
if (! empty($id) && $action == 'edit')
{
2015-03-21 07:12:32 +01:00
$result=$object->fetch($id);
if ($result < 0) {
dol_print_error($db,$object->error); exit;
}
$result=$object->fetch_optionals($object->id,$extralabels);
if ($result < 0) {
dol_print_error($db); exit;
}
2008-11-15 19:20:40 +01:00
2015-03-16 06:29:15 +01:00
$head = donation_prepare_head($object);
2010-04-05 03:25:44 +02:00
dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
2008-11-15 19:20:40 +01:00
2015-03-16 06:29:15 +01:00
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-11-15 19:20:40 +01:00
print '<table class="border" width="100%">';
print '<input type="hidden" name="action" value="update">';
2015-03-16 06:29:15 +01:00
print '<input type="hidden" name="rowid" value="'.$object->id.'">';
2015-03-29 09:20:32 +02:00
print '<input type="hidden" name="amount" value="'.$object->amount.'">';
2008-11-15 19:20:40 +01:00
// Ref
print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
2015-03-16 06:29:15 +01:00
print $object->getNomUrl();
2008-11-15 19:20:40 +01:00
print '</td>';
print '</tr>';
2008-11-15 19:13:25 +01:00
2011-06-12 17:47:10 +02:00
$nbrows=12;
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled)) $nbrows++;
2011-06-12 17:47:10 +02:00
2015-03-29 09:20:32 +02:00
// Date
2011-06-12 17:47:10 +02:00
print "<tr>".'<td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td>';
2015-03-16 06:29:15 +01:00
$form->select_date($object->date,'','','','',"update");
2008-11-15 19:20:40 +01:00
print '</td>';
2008-11-15 19:13:25 +01:00
2011-06-12 17:47:10 +02:00
// Amount
2015-03-29 09:20:32 +02:00
if ($object->statut == 0)
{
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>';
}
else
{
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
print price($object->amount,0,$langs,0,0,-1,$conf->currency);
print '</td></tr>';
}
2008-11-15 19:20:40 +01:00
print '<tr><td class="fieldrequired">'.$langs->trans("PublicDonation")."</td><td>";
print $form->selectyesno("public",1,1);
2008-11-15 19:20:40 +01:00
print "</td>";
print "</tr>\n";
$langs->load("companies");
2015-03-16 06:29:15 +01:00
print "<tr>".'<td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$object->societe.'"></td></tr>';
print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td><input type="text" name="lastname" size="40" value="'.$object->lastname.'"></td></tr>';
print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td><input type="text" name="firstname" size="40" value="'.$object->firstname.'"></td></tr>';
2008-11-15 19:20:40 +01:00
print "<tr>".'<td>'.$langs->trans("Address").'</td><td>';
2015-03-16 06:29:15 +01:00
print '<textarea name="address" wrap="soft" cols="40" rows="'.ROWS_3.'">'.$object->address.'</textarea></td></tr>';
2011-06-12 17:47:10 +02:00
// Zip / Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
2015-03-16 06:29:15 +01:00
print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6);
2011-06-12 17:47:10 +02:00
print ' ';
2015-03-16 06:29:15 +01:00
print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
2015-03-18 21:56:00 +01:00
print '</tr>';
2011-06-12 17:47:10 +02:00
2015-03-16 06:29:15 +01:00
// Country
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>';
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" size="40" value="'.$object->email.'"></td></tr>';
2008-11-15 19:20:40 +01:00
2011-06-12 17:47:10 +02:00
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
2015-03-18 05:07:32 +01:00
if ($object->modepaymentid) $selected = $object->modepaymentid;
else $selected = '';
2015-03-18 05:07:32 +01:00
$form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
2011-06-12 17:47:10 +02:00
print "</td></tr>\n";
2008-11-15 19:20:40 +01:00
2015-03-16 06:29:15 +01:00
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
2008-11-15 19:20:40 +01:00
2011-06-12 17:47:10 +02:00
// Project
2012-07-11 10:14:56 +02:00
if (! empty($conf->projet->enabled))
2011-06-12 17:47:10 +02:00
{
$formproject=new FormProjets($db);
2011-06-12 17:47:10 +02:00
$langs->load('projects');
print '<tr><td>'.$langs->trans('Project').'</td><td>';
$formproject->select_projects(-1, $object->fk_projet,'fk_projet', 0, 1, 0, 1);
2011-06-12 17:47:10 +02:00
print '</td></tr>';
}
// Other attributes
2015-03-25 22:37:14 +01:00
$parameters=array('colspan' => ' colspan="2"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields,'edit');
}
2008-11-15 19:20:40 +01:00
print "</table>\n";
2010-04-05 03:25:44 +02:00
2014-11-25 20:13:43 +01:00
print '<br><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>';
2010-04-05 03:25:44 +02:00
2008-11-15 19:20:40 +01:00
print "</form>\n";
print "</div>\n";
}
/* ************************************************************ */
/* */
2015-03-18 05:07:32 +01:00
/* Donation card in view mode */
/* */
/* ************************************************************ */
2012-07-11 10:14:56 +02:00
if (! empty($id) && $action != 'edit')
2002-12-19 19:55:38 +01:00
{
2015-03-26 20:43:34 +01:00
// Confirmation delete
if ($action == 'delete')
{
$text=$langs->trans("ConfirmDeleteADonation");
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1);
}
2015-03-16 06:29:15 +01:00
$result=$object->fetch($id);
2015-03-21 07:12:32 +01:00
if ($result < 0) {
dol_print_error($db,$object->error); exit;
}
$result=$object->fetch_optionals($object->id,$extralabels);
if ($result < 0) {
dol_print_error($db); exit;
}
2015-03-16 06:29:15 +01:00
$head = donation_prepare_head($object);
2010-04-05 03:25:44 +02:00
dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
2008-11-15 19:20:40 +01:00
2015-03-16 06:29:15 +01:00
print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2008-11-15 19:20:40 +01:00
print '<table class="border" width="100%">';
2015-03-25 22:37:14 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
2012-07-28 21:22:59 +02:00
2011-06-12 17:47:10 +02:00
$nbrows=12;
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled)) $nbrows++;
2011-06-12 17:47:10 +02:00
2008-11-15 19:20:40 +01:00
// Ref
print "<tr>".'<td>'.$langs->trans("Ref").'</td><td colspan="2">';
2015-03-16 06:29:15 +01:00
print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', '');
2008-11-15 19:20:40 +01:00
print '</td>';
2008-11-15 19:13:25 +01:00
print '</tr>';
2009-01-15 02:14:03 +01:00
2008-11-15 19:13:25 +01:00
// Date
2015-03-18 21:56:00 +01:00
print '<tr><td width="25%">'.$langs->trans("Date").'</td><td colspan="2">';
2015-03-16 06:29:15 +01:00
print dol_print_date($object->date,"day");
2008-11-15 19:20:40 +01:00
print "</td>";
2015-03-18 21:56:00 +01:00
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">';
print price($object->amount,0,$langs,0,0,-1,$conf->currency);
print '</td></tr>';
2008-11-15 19:20:40 +01:00
2015-03-18 21:56:00 +01:00
print '<tr><td>'.$langs->trans("PublicDonation").'</td><td colspan="2">';
2015-03-16 06:29:15 +01:00
print yn($object->public);
2015-03-18 21:56:00 +01:00
print '</td></tr>';
2015-03-21 18:00:16 +01:00
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
print '<tr><td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($object->address).'</td>';
2015-03-18 21:56:00 +01:00
$rowspan=6;
if (! empty($conf->projet->enabled)) $rowspan++;
print '<td rowspan="'.$rowspan.'" valign="top">';
/*
* Payments
*/
2015-03-29 09:20:32 +02:00
$sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,";
2015-03-18 21:56:00 +01:00
$sql.= "c.code as type_code,c.libelle as paiement_type";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p";
$sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
$sql.= ", ".MAIN_DB_PREFIX."don as d";
2015-03-21 18:00:16 +01:00
$sql.= " WHERE d.rowid = '".$id."'";
2015-03-18 21:56:00 +01:00
$sql.= " AND p.fk_donation = d.rowid";
$sql.= " AND d.entity = ".$conf->entity;
$sql.= " AND p.fk_typepayment = c.id";
2015-03-29 09:20:32 +02:00
$sql.= " ORDER BY dp";
2015-03-18 21:56:00 +01:00
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0; $total = 0;
print '<table class="nobordernopadding" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("RefPayment").'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Amount").'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr ".$bc[$var]."><td>";
2015-03-29 09:20:32 +02:00
print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
2015-03-18 21:56:00 +01:00
print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
$labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type;
print "<td>".$labeltype.' '.$object->num_paiement."</td>\n";
2015-03-21 18:00:16 +01:00
print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
2015-03-18 21:56:00 +01:00
print "</tr>";
2015-03-21 18:00:16 +01:00
$totalpaid += $objp->amount;
2015-03-18 21:56:00 +01:00
$i++;
}
if ($object->paid == 0)
{
2015-03-21 18:00:16 +01:00
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";
2015-03-18 21:56:00 +01:00
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";
2008-11-15 19:20:40 +01:00
2015-03-18 21:56:00 +01:00
$remaintopay = $object->amount - $totalpaid;
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
2015-03-21 18:00:16 +01:00
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
2015-03-18 21:56:00 +01:00
}
print "</table>";
$db->free($resql);
}
else
{
dol_print_error($db);
}
print "</td>";
print "</tr>";
2011-06-12 17:47:10 +02:00
// Zip / Town
2015-03-18 21:56:00 +01:00
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
print $object->zip.($object->zip && $object->town?' / ':'').$object->town.'</td></tr>';
2011-06-12 17:47:10 +02:00
// Country
2015-03-18 21:56:00 +01:00
print '<tr><td>'.$langs->trans('Country').'</td><td>';
2015-03-16 06:29:15 +01:00
if (! empty($object->country_code))
{
$img=picto_from_langcode($object->country_code);
print ($img?$img.' ':'');
2015-03-18 05:07:32 +01:00
print $object->country;
2015-03-16 06:29:15 +01:00
}
2015-03-18 05:07:32 +01:00
else
{
print $object->country_olddata;
}
2015-03-16 06:29:15 +01:00
print '</td></tr>';
2011-06-12 17:47:10 +02:00
// EMail
2015-03-16 06:29:15 +01:00
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email).'</td></tr>';
2011-06-12 17:47:10 +02:00
// Payment mode
2008-11-15 19:20:40 +01:00
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
2015-03-18 05:07:32 +01:00
$form->form_modes_reglement(null, $object->modepaymentid,'none');
2008-11-15 19:20:40 +01:00
print "</td></tr>\n";
2015-03-16 06:29:15 +01:00
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
2008-11-15 19:20:40 +01:00
2011-06-12 17:47:10 +02:00
// Project
2012-09-15 10:01:35 +02:00
if (! empty($conf->projet->enabled))
2011-06-12 17:47:10 +02:00
{
2015-03-18 06:29:10 +01:00
print '<tr>';
print '<td>'.$langs->trans("Project").'</td>';
print '<td>'.$object->projet.'</td>';
print '</tr>';
2011-06-12 17:47:10 +02:00
}
// Other attributes
2015-03-25 22:37:14 +01:00
$parameters=array('colspan' => ' colspan="2"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields);
}
2008-11-15 19:20:40 +01:00
print "</table>\n";
print "</form>\n";
print "</div>";
2015-03-18 05:07:32 +01:00
$remaintopay = $object->amount - $totalpaid;
2009-01-15 02:14:03 +01:00
2008-11-15 19:20:40 +01:00
/**
2015-03-18 05:07:32 +01:00
* Actions buttons
2008-11-15 19:20:40 +01:00
*/
print '<div class="tabsAction">';
2015-03-18 05:07:32 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2015-03-16 06:29:15 +01:00
if ($object->statut == 0)
2008-11-15 19:20:40 +01:00
{
2015-03-18 05:07:32 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
2008-11-15 19:20:40 +01:00
}
2002-12-21 18:34:05 +01:00
2015-03-18 05:07:32 +01:00
if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0)
2011-06-12 17:47:10 +02:00
{
2015-03-18 05:07:32 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
2011-06-12 17:47:10 +02:00
}
2015-03-18 05:07:32 +01:00
// Create payment
if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer)
2008-11-15 19:20:40 +01:00
{
2015-03-18 05:07:32 +01:00
if ($remaintopay == 0)
{
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
}
else
{
2015-03-25 22:37:14 +01:00
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>';
2015-03-18 05:07:32 +01:00
}
2008-11-15 19:20:40 +01:00
}
2015-03-18 05:07:32 +01:00
// Classify 'paid'
if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
}
2015-03-26 20:43:34 +01:00
// Delete
2008-11-15 19:20:40 +01:00
if ($user->rights->don->supprimer)
{
2015-03-18 05:07:32 +01:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
2008-11-15 19:20:40 +01:00
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("Delete")."</a></div>";
2008-11-15 19:20:40 +01:00
}
2002-12-19 19:55:38 +01:00
2008-11-15 19:20:40 +01:00
print "</div>";
print '<table width="100%"><tr><td width="50%" valign="top">';
/*
2009-11-30 02:12:54 +01:00
* Documents generes
*/
2015-03-16 06:29:15 +01:00
$filename=dol_sanitizeFileName($object->id);
$filedir=$conf->don->dir_output . '/' . get_exdir($filename,2);
2015-03-16 06:29:15 +01:00
$urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id;
2008-11-15 19:20:40 +01:00
// $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
// $delallowed=$user->rights->facture->supprimer;
2008-11-14 12:56:47 +01:00
$genallowed=1;
$delallowed=0;
$var=true;
print '<br>';
2008-11-14 12:56:47 +01:00
$formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed);
2008-11-15 19:20:40 +01:00
print '</td><td>&nbsp;</td>';
2008-11-15 19:20:40 +01:00
print '</tr></table>';
2002-12-26 11:22:14 +01:00
2002-12-19 19:55:38 +01:00
}
llxFooter();
2015-03-18 06:29:10 +01:00
$db->close();