dolibarr/htdocs/adherents/subscription/card.php

407 lines
14 KiB
PHP
Raw Normal View History

<?php
2019-08-02 12:04:06 +02:00
/* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
2020-11-02 18:35:39 +01:00
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
*
* 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
* (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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
2019-01-17 18:08:14 +01:00
* \file htdocs/adherents/subscription/card.php
* \ingroup member
* \brief Page to add/edit/remove a member subscription
*/
require '../../main.inc.php';
2019-01-17 18:08:14 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
2019-01-17 17:37:39 +01:00
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
if (!empty($conf->banque->enabled)) {
2019-01-17 18:08:14 +01:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array("companies", "members", "bills", "users"));
2019-01-17 18:08:14 +01:00
$adh = new Adherent($db);
$adht = new AdherentType($db);
$object = new Subscription($db);
$errmsg = '';
2019-01-17 18:08:14 +01:00
$action = GETPOST("action", 'alpha');
2020-11-02 18:35:39 +01:00
$rowid = GETPOST("rowid", "int") ? GETPOST("rowid", "int") : GETPOST("id", "int");
$typeid = GETPOST("typeid", "int");
$cancel = GETPOST('cancel', 'alpha');
$confirm = GETPOST('confirm');
2020-11-02 18:35:39 +01:00
$note = GETPOST('note', 'alpha');
$typeid = (int) GETPOST('typeid', 'int');
2020-11-02 20:15:03 +01:00
$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
2021-10-22 22:15:59 +02:00
if (empty($user->rights->adherent->cotisation->lire)) {
2019-01-17 18:08:14 +01:00
accessforbidden();
2021-03-01 00:19:52 +01:00
}
2019-01-17 18:08:14 +01:00
$permissionnote = $user->rights->adherent->cotisation->creer; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user->rights->adherent->cotisation->creer; // Used by the include of actions_dellink.inc.php
2019-01-17 18:08:14 +01:00
$permissiontoedit = $user->rights->adherent->cotisation->creer; // Used by the include of actions_lineupdonw.inc.php
$hookmanager->initHooks(array('subscriptioncard', 'globalcard'));
// Security check
$result = restrictedArea($user, 'subscription', 0); // TODO Check on object id
2021-02-14 21:56:15 +01:00
/*
2019-01-17 18:08:14 +01:00
* Actions
*/
2021-03-01 00:19:52 +01:00
if ($cancel) {
$action = '';
}
2019-01-17 18:08:14 +01:00
//include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
2019-01-17 18:08:14 +01:00
//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
2019-01-17 18:08:14 +01:00
2020-05-21 09:12:18 +02:00
if ($user->rights->adherent->cotisation->creer && $action == 'update' && !$cancel) {
2019-09-20 15:07:58 +02:00
// Load current object
$result = $object->fetch($rowid);
2020-05-21 09:12:18 +02:00
if ($result > 0) {
2019-01-17 18:08:14 +01:00
$db->begin();
$errmsg = '';
2020-05-21 09:12:18 +02:00
if ($object->fk_bank) {
$accountline = new AccountLine($db);
$result = $accountline->fetch($object->fk_bank);
2019-01-17 18:08:14 +01:00
// If transaction consolidated
2020-05-21 09:12:18 +02:00
if ($accountline->rappro) {
$errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
2020-05-21 00:47:16 +02:00
} else {
2022-02-22 23:44:56 +01:00
$accountline->datev = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
$accountline->dateo = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
2020-11-02 18:35:39 +01:00
$accountline->amount = $amount;
$result = $accountline->update($user);
2020-05-21 09:12:18 +02:00
if ($result < 0) {
$errmsg = $accountline->error;
2019-01-17 18:08:14 +01:00
}
}
}
2020-05-21 09:12:18 +02:00
if (!$errmsg) {
2019-09-20 15:07:58 +02:00
// Modify values
2022-02-22 23:44:56 +01:00
$object->dateh = dol_mktime(GETPOST('datesubhour', 'int'), GETPOST('datesubmin', 'int'), 0, GETPOST('datesubmonth', 'int'), GETPOST('datesubday', 'int'), GETPOST('datesubyear', 'int'));
$object->datef = dol_mktime(GETPOST('datesubendhour', 'int'), GETPOST('datesubendmin', 'int'), 0, GETPOST('datesubendmonth', 'int'), GETPOST('datesubendday', 'int'), GETPOST('datesubendyear', 'int'));
2020-11-02 18:35:39 +01:00
$object->fk_type = $typeid;
$object->note_public = $note;
2022-02-22 23:44:56 +01:00
$object->note_private = $note;
2020-11-02 18:35:39 +01:00
$object->amount = $amount;
2019-01-17 18:08:14 +01:00
$result = $object->update($user);
2020-05-21 09:12:18 +02:00
if ($result >= 0 && !count($object->errors)) {
2019-01-17 18:08:14 +01:00
$db->commit();
header("Location: card.php?rowid=".$object->id);
exit;
2020-05-21 00:47:16 +02:00
} else {
2019-01-17 18:08:14 +01:00
$db->rollback();
if ($object->error) {
$errmsg = $object->error;
2020-05-21 00:47:16 +02:00
} else {
2020-05-21 09:12:18 +02:00
foreach ($object->errors as $error) {
2021-03-01 00:19:52 +01:00
if ($errmsg) {
$errmsg .= '<br>';
}
$errmsg .= $error;
2019-01-17 18:08:14 +01:00
}
}
$action = '';
2019-01-17 18:08:14 +01:00
}
2020-05-21 00:47:16 +02:00
} else {
2019-01-17 18:08:14 +01:00
$db->rollback();
}
}
2019-01-17 17:37:39 +01:00
}
2019-01-17 18:08:14 +01:00
2020-05-21 09:12:18 +02:00
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->adherent->cotisation->creer) {
$result = $object->fetch($rowid);
$result = $object->delete($user);
if ($result > 0) {
header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
exit;
} else {
$mesg = $adh->error;
}
2019-01-17 17:37:39 +01:00
}
2016-12-17 19:21:48 +01:00
2009-01-21 13:20:58 +01:00
2019-01-17 18:08:14 +01:00
/*
* View
*/
2019-01-17 18:08:14 +01:00
$form = new Form($db);
2021-02-16 11:15:42 +01:00
$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros';
llxHeader('', $langs->trans("SubscriptionCard"), $help_url);
2009-01-21 13:20:58 +01:00
2019-01-17 18:08:14 +01:00
dol_htmloutput_errors($errmsg);
2009-01-21 13:20:58 +01:00
2017-07-08 00:42:55 +02:00
2020-05-21 09:12:18 +02:00
if ($user->rights->adherent->cotisation->creer && $action == 'edit') {
2019-01-17 18:08:14 +01:00
/********************************************
*
* Subscription card in edit mode
*
********************************************/
2017-07-08 00:42:55 +02:00
$object->fetch($rowid);
$result = $adh->fetch($object->fk_adherent);
2017-07-08 00:42:55 +02:00
2019-01-17 18:08:14 +01:00
$head = subscription_prepare_head($object);
2019-01-17 18:08:14 +01:00
print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-01-17 18:08:14 +01:00
print "<input type=\"hidden\" name=\"action\" value=\"update\">";
print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
2009-01-21 13:20:58 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2008-01-26 00:04:01 +01:00
print "\n";
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">';
// Ref
print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
2019-01-17 18:08:14 +01:00
print '<td class="valeur" colspan="3">';
print $form->showrefnav($object, 'rowid', $linkback, 1);
print '</td></tr>';
2019-08-02 12:04:06 +02:00
// Member
$adh->ref = $adh->getFullName($langs);
2019-08-02 12:04:06 +02:00
print '<tr>';
print '<td>'.$langs->trans("Member").'</td><td class="valeur" colspan="3">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
print '</tr>';
// Type
2019-01-17 18:08:14 +01:00
print '<tr>';
print '<td>'.$langs->trans("Type").'</td><td class="valeur" colspan="3">';
2020-02-16 19:33:58 +01:00
print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
2019-01-17 18:08:14 +01:00
print'</td></tr>';
// Date start subscription
print '<tr><td>'.$langs->trans("DateSubscription").'</td><td class="valeur" colspan="2">';
2019-01-17 18:08:14 +01:00
print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
2019-01-17 17:37:39 +01:00
print '</td>';
print '</tr>';
// Date end subscription
print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur" colspan="2">';
2019-01-17 18:08:14 +01:00
print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
2019-01-17 17:37:39 +01:00
print '</td>';
print '</tr>';
2012-07-28 21:49:47 +02:00
// Amount
print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
2019-01-17 18:08:14 +01:00
print '<input type="text" class="flat" size="10" name="amount" value="'.price($object->amount).'"></td></tr>';
2017-07-08 00:42:55 +02:00
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur" colspan="2">';
2019-01-17 18:08:14 +01:00
print '<input type="text" class="flat" size="60" name="note" value="'.$object->note.'"></td></tr>';
2017-07-08 00:42:55 +02:00
2019-01-17 18:08:14 +01:00
// Bank line
2020-11-02 18:35:39 +01:00
if (!empty($conf->banque->enabled) && ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)) {
print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur" colspan="2">';
if ($object->fk_bank) {
$bankline = new AccountLine($db);
$result = $bankline->fetch($object->fk_bank);
print $bankline->getNomUrl(1, 0, 'showall');
} else {
print $langs->trans("NoneF");
2019-01-17 18:08:14 +01:00
}
2020-11-02 18:35:39 +01:00
print '</td></tr>';
2019-01-17 18:08:14 +01:00
}
2017-07-08 00:42:55 +02:00
2019-01-17 18:08:14 +01:00
print '</table>';
2017-07-08 00:42:55 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
print $form->buttonsSaveCancel();
2012-04-02 10:50:20 +02:00
2019-01-17 18:08:14 +01:00
print '</form>';
print "\n";
2019-01-17 17:37:39 +01:00
}
2019-01-17 18:08:14 +01:00
2020-05-21 09:12:18 +02:00
if ($rowid && $action != 'edit') {
2019-01-17 18:08:14 +01:00
/********************************************
*
* Subscription card in view mode
*
********************************************/
$result = $object->fetch($rowid);
$result = $adh->fetch($object->fk_adherent);
2019-01-17 18:08:14 +01:00
$head = subscription_prepare_head($object);
2009-01-21 13:20:58 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
2019-01-17 18:08:14 +01:00
// Confirmation to delete subscription
if ($action == 'delete') {
2019-01-17 18:08:14 +01:00
//$formquestion=array();
//$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
$text = $langs->trans("ConfirmDeleteSubscription");
2021-03-01 00:19:52 +01:00
if (!empty($conf->banque->enabled) && !empty($conf->global->ADHERENT_BANK_USE)) {
$text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
}
print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
}
2019-01-17 18:08:14 +01:00
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-01-17 18:08:14 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2019-01-17 18:08:14 +01:00
dol_banner_tab($object, 'rowid', $linkback, 1);
2019-01-17 18:08:14 +01:00
print '<div class="fichecenter">';
2019-01-17 18:08:14 +01:00
print '<div class="underbanner clearboth"></div>';
2009-01-21 13:20:58 +01:00
print '<table class="border centpercent">';
// Member
$adh->ref = $adh->getFullName($langs);
print '<tr>';
print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(1, 0, 'subscription').'</td>';
print '</tr>';
2019-08-02 12:04:06 +02:00
// Type
print '<tr>';
print '<td class="titlefield">'.$langs->trans("Type").'</td>';
print '<td class="valeur">';
if ($object->fk_type > 0 || $adh->typeid > 0) {
$typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
$adht->fetch($typeid);
print $adht->getNomUrl(1);
} else {
print $langs->trans("NoType");
}
print '</td></tr>';
2019-01-17 18:08:14 +01:00
// Date subscription
print '<tr>';
print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
print '</tr>';
2019-01-17 18:08:14 +01:00
// Date end subscription
print '<tr>';
print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
print '</tr>';
2019-01-17 18:08:14 +01:00
// Amount
print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($object->amount).'</td></tr>';
2019-01-17 18:08:14 +01:00
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur">'.$object->note.'</td></tr>';
2019-01-17 18:08:14 +01:00
// Bank line
2020-11-02 18:35:39 +01:00
if (!empty($conf->banque->enabled) && ($conf->global->ADHERENT_BANK_USE || $object->fk_bank)) {
print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
if ($object->fk_bank) {
$bankline = new AccountLine($db);
$result = $bankline->fetch($object->fk_bank);
print $bankline->getNomUrl(1, 0, 'showall');
} else {
print $langs->trans("NoneF");
}
2020-11-02 18:35:39 +01:00
print '</td></tr>';
}
print "</table>\n";
print '</div>';
2009-01-21 13:20:58 +01:00
print '</form>';
2009-01-21 13:20:58 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2019-01-17 18:08:14 +01:00
/*
2021-03-16 04:22:55 +01:00
* Action bar
2021-03-01 00:19:52 +01:00
*/
print '<div class="tabsAction">';
2019-01-17 18:08:14 +01:00
if ($user->rights->adherent->cotisation->creer) {
2020-05-21 09:12:18 +02:00
if (!$bankline->rappro) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
2020-05-21 00:47:16 +02:00
} else {
2019-01-17 18:08:14 +01:00
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated")."\" href=\"#\">".$langs->trans("Modify")."</a></div>";
}
}
// Delete
if ($user->rights->adherent->cotisation->creer) {
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
}
2019-01-17 18:08:14 +01:00
print '</div>';
2017-07-08 00:42:55 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
2017-07-08 00:42:55 +02:00
2021-03-16 04:04:18 +01:00
// Generated documents
/*
2021-03-01 00:19:52 +01:00
$filename = dol_sanitizeFileName($object->ref);
$filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
$urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
$genallowed = $user->rights->facture->lire;
$delallowed = $user->rights->facture->creer;
print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
$somethingshown = $formfile->numoffiles;
*/
2019-01-17 18:08:14 +01:00
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription'));
$somethingshown = $form->showLinkedObjectBlock($object, '');
2019-01-17 18:08:14 +01:00
// Show links to link elements
/*$linktoelem = $form->showLinkToObjectBlock($object,array('order'));
2019-01-17 18:08:14 +01:00
if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem;
2021-03-01 00:19:52 +01:00
*/
2019-01-17 18:08:14 +01:00
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">';
2019-01-17 18:08:14 +01:00
// List of actions on element
/*
2021-03-01 00:19:52 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
$formactions = new FormActions($db);
$somethingshown = $formactions->showactions($object, $object->element, $socid, 1);
2021-03-01 00:19:52 +01:00
*/
2019-01-17 18:08:14 +01:00
2021-10-23 17:18:35 +02:00
print '</div></div>';
2019-01-17 18:08:14 +01:00
}
2018-07-28 14:29:28 +02:00
// End of page
llxFooter();
$db->close();