*
* 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 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
\file htdocs/adherents/fiche_subscription.php
\ingroup adherent
\brief Page d'ajout, edition, suppression d'une fiche adhésion
\version $Id$
*/
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/cotisation.class.php");
require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("members");
$langs->load("users");
$adh = new Adherent($db);
$subscription = new Cotisation($db);
$errmsg='';
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"];
$typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"];
if (! $user->rights->adherent->cotisation->lire)
accessforbidden();
/*
* Actions
*/
if ($user->rights->adherent->cotisation->creer && $_REQUEST["action"] == 'update' && ! $_POST["cancel"])
{
// Charge objet actuel
$result=$subscription->fetch($_POST["rowid"]);
if ($result > 0)
{
$db->begin();
$errmsg='';
if ($subscription->fk_bank)
{
$accountline=new AccountLine($db);
$result=$accountline->fetch($subscription->fk_bank);
// If transaction consolidated
if ($accountline->rappro)
{
$errmsg=$langs->trans("SubscriptionLinkedToConciliatedTrnasaction");
}
else
{
$accountline->datev=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
$accountline->dateo=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
$accountline->amount=$_POST["amount"];
$result=$accountline->update($user);
if ($result < 0)
{
$errmsg=$accountline->error;
}
}
}
if (! $errmsg)
{
// Modifie valeures
$subscription->dateh=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
$subscription->datef=dolibarr_mktime($_POST['datesubendhour'], $_POST['datesubendmin'], 0, $_POST['datesubendmonth'], $_POST['datesubendday'], $_POST['datesubendyear']);
$subscription->amount=$_POST["amount"];
//print 'datef='.$subscription->datef.' '.$_POST['datesubendday'];
$result=$subscription->update($user);
if ($result >= 0 && ! sizeof($subscription->errors))
{
$db->commit();
header("Location: fiche_subscription.php?rowid=".$subscription->id);
exit;
}
else
{
$db->rollback();
if ($subscription->error)
{
$errmsg=$subscription->error;
}
else
{
foreach($subscription->errors as $error)
{
if ($errmsg) $errmsg.='
';
$errmsg.=$error;
}
}
$action='';
}
}
else
{
$db->rollback();
}
}
}
if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
{
$result=$subscription->fetch($rowid);
$result=$subscription->delete();
if ($result > 0)
{
Header("Location: card_subscriptions.php?rowid=".$subscription->fk_adherent);
exit;
}
else
{
$mesg=$adh->error;
}
}
/*
*
*/
llxHeader();
$form = new Form($db);
if ($errmsg)
{
print '