2
0
forked from Wavyzz/dolibarr

Merge pull request #22705 from fboitel/NEW#22622-thirdparty-partnership

NEW #22622: all partneships displayed on tab partnership of thirdparties and members
This commit is contained in:
Laurent Destailleur
2022-11-01 21:11:06 +01:00
committed by GitHub
6 changed files with 180 additions and 289 deletions

View File

@@ -267,9 +267,23 @@ function societe_prepare_head(Societe $object)
if (!empty($user->rights->partnership->read)) {
$langs->load("partnership");
$nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
$head[$h][0] = DOL_URL_ROOT.'/societe/partnership.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Partnership");
$head[$h][2] = 'partnership';
$head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Partnerships");
$nbNote = 0;
$sql = "SELECT COUNT(n.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
$sql .= " WHERE fk_soc = ".((int) $object->id);
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbNote = $obj->nb;
} else {
dol_print_error($db);
}
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
$head[$h][2] = 'partnerships';
if ($nbPartnership > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
}

View File

@@ -66,9 +66,23 @@ function member_prepare_head(Adherent $object)
if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
if (!empty($user->rights->partnership->read)) {
$nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
$head[$h][0] = DOL_URL_ROOT.'/adherents/partnership.php?rowid='.$object->id;
$head[$h][1] = $langs->trans("Partnership");
$head[$h][2] = 'partnership';
$head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?rowid='.$object->id;
$head[$h][1] = $langs->trans("Partnerships");
$nbNote = 0;
$sql = "SELECT COUNT(n.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
$sql .= " WHERE fk_member = ".((int) $object->id);
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbNote = $obj->nb;
} else {
dol_print_error($db);
}
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
$head[$h][2] = 'partnerships';
if ($nbPartnership > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
}

View File

@@ -20,6 +20,7 @@ ModulePartnershipName=Partnership management
PartnershipDescription=Module Partnership management
PartnershipDescriptionLong= Module Partnership management
Partnership=Partnership
Partnerships=Partnerships
AddPartnership=Add partnership
CancelPartnershipForExpiredMembers=Partnership: Cancel partnership of members with expired subscriptions
PartnershipCheckBacklink=Partnership: Check referring backlink
@@ -49,8 +50,8 @@ PublicFormRegistrationPartnerDesc=Dolibarr can provide you a public URL/website
# Object
#
DeletePartnership=Delete a partnership
PartnershipDedicatedToThisThirdParty=Partnership dedicated to this third party
PartnershipDedicatedToThisMember=Partnership dedicated to this member
PartnershipDedicatedToThisThirdParty=Partnership dedicated to this third party
PartnershipDedicatedToThisMember=Partnership dedicated to this member
DatePartnershipStart=Start date
DatePartnershipEnd=End date
ReasonDecline=Decline reason

View File

@@ -20,6 +20,7 @@ ModulePartnershipName=Gestion des partenariats
PartnershipDescription=Module de gestion des partenariats
PartnershipDescriptionLong= Module de gestion des partenariats
Partnership=Partenariat
Partnerships=Partenariats
AddPartnership=Ajouter un partenariat
CancelPartnershipForExpiredMembers=Partenariat : annuler le partenariat des adhérents dont les cotisations ont expirés
PartnershipCheckBacklink=Partenariat : Vérifiez le backlink référent

View File

@@ -28,7 +28,9 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
// for other modules
@@ -49,7 +51,8 @@ $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '
$mode = GETPOST('mode', 'aZ');
$id = GETPOST('id', 'int');
$socid = GETPOST('socid', 'int');
$memberid = GETPOST('rowid', 'int');
// Load variable for pagination
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
@@ -68,7 +71,13 @@ $object = new Partnership($db);
$extrafields = new ExtraFields($db);
$adherent = new Adherent($db);
$diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('partnershiplist')); // Note that conf->hooks_modules contains array
if ($socid > 0) {
$hookmanager->initHooks(array('thirdpartypartnership'));
} elseif ($memberid > 0) {
$hookmanager->initHooks(array('memberpartnership'));
} else {
$hookmanager->initHooks(array('partnershiplist')); // Note that conf->hooks_modules contains array
}
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
@@ -144,7 +153,6 @@ $permissiontodelete = $user->rights->partnership->delete;
if (empty($conf->partnership->enabled)) {
accessforbidden('Module not enabled');
}
$socid = 0;
if ($user->socid > 0) { // Protection if external user
//$socid = $user->socid;
accessforbidden();
@@ -325,9 +333,19 @@ if ($object->ismultientitymanaged == 1) {
} else {
$sql .= " WHERE 1 = 1";
}
if ($managedfor == 'member')
$sql .= " AND fk_member > 0";
else $sql .= " AND fk_soc > 0";
if ($managedfor == 'member') {
if ($memberid > 0) {
$sql .= " AND t.fk_member = ".((int) $memberid);
} else {
$sql .= " AND fk_member > 0";
}
} else {
if ($socid > 0) {
$sql .= " AND t.fk_soc = ".((int) $socid);
} else {
$sql .= " AND fk_soc > 0";
}
}
foreach ($search as $key => $val) {
if (array_key_exists($key, $object->fields)) {
if ($key == 'status' && $search[$key] == -1) {
@@ -449,6 +467,113 @@ if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
if ($managedfor == "member") {
if ($memberid > 0 && $user->hasRight('adherent', 'lire')) {
$langs->load("members");
$adhstat = new Adherent($db);
$adht = new AdherentType($db);
$result = $adhstat->fetch($memberid);
if (isModEnabled('notification')) {
$langs->load("mails");
}
$adht->fetch($adhstat->typeid);
$head = member_prepare_head($adhstat);
print dol_get_fiche_head($head, 'partnerships', $langs->trans("ThirdParty"), -1, 'user');
$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'rowid', $linkback);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Login
if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
}
// Type
print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
// Morphy
print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$adhstat->getmorphylib().'</td>';
print '</tr>';
// Company
print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$adhstat->company.'</td></tr>';
// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$adhstat->getCivilityLabel().'&nbsp;</td>';
print '</tr>';
print '</table>';
print '</div>';
print dol_get_fiche_end();
}
} elseif ($managedfor == "thirdparty") {
if ($socid && $user->hasRight('societe', 'lire')) {
$socstat = new Societe($db);
$res = $socstat->fetch($socid);
if ($res > 0) {
$tmpobject = $object;
$object = $socstat; // $object must be of type Societe when calling societe_prepare_head
$head = societe_prepare_head($socstat);
$object = $tmpobject;
print dol_get_fiche_head($head, 'partnerships', $langs->trans("ThirdParty"), -1, 'company');
dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
// Type Prospect/Customer/Supplier
print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
print $socstat->getTypeUrl(1);
print '</td></tr>';
// Customer code
if ($socstat->client && !empty($socstat->code_client)) {
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td>';
print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
$tmpcheck = $socstat->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
}
print '</td>';
print '</tr>';
}
// Supplier code
if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td>';
print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
$tmpcheck = $socstat->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
}
print '</td>';
print '</tr>';
}
print '</table>';
print '</div>';
print dol_get_fiche_end();
}
}
}
$arrayofselected = is_array($toselect) ? $toselect : array();
@@ -459,6 +584,12 @@ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($socid) {
$param .= '&socid='.urlencode($socid);
}
if ($memberid) {
$param .= '&rowid='.urlencode($memberid);
}
foreach ($search as $key => $val) {
if (is_array($search[$key]) && count($search[$key])) {
foreach ($search[$key] as $skey) {
@@ -512,7 +643,11 @@ print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
if ($socid) {
print '<input type="hidden" name="socid" value="'.$socid.'" >';
} elseif ($memberid) {
print '<input type="hidden" name="rowid" value="'.$memberid.'" >';
}
$newcardbutton = '';
$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/partnership/partnership_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);

View File

@@ -1,274 +0,0 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2021 NextGestion <contact@nextgestion.com>
* Copyright (C) 2022 Charlene Benke <charlent@patas-monkey.com>
*
* 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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file partnership_card.php
* \ingroup partnership
* \brief Page to create/edit/view partnership
*/
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
// Load translation files required by the page
$langs->loadLangs(array("companies", "partnership", "other"));
// Get parameters
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'partnershipcard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
//$lineid = GETPOST('lineid', 'int');
// Security check
$socid = GETPOST('socid', 'int');
if (!empty($user->socid)) {
$socid = $user->socid;
}
if (empty($id) && $socid && (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty')) {
$id = $socid;
}
$object = new Societe($db);
if ($id > 0) {
$object->fetch($id);
}
// Initialize technical objects
$object = new Partnership($db);
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('thirdpartypartnership', 'globalcard')); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
// Initialize array of search criterias
$search_all = GETPOST("search_all", 'alpha');
$search = array();
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha')) {
$search[$key] = GETPOST('search_'.$key, 'alpha');
}
}
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
$permissiontoread = $user->rights->partnership->read;
$permissiontoadd = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$permissiontodelete = $user->rights->partnership->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
$permissionnote = $user->rights->partnership->write; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user->rights->partnership->write; // Used by the include of actions_dellink.inc.php
$usercanclose = $user->rights->partnership->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1];
if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') != 'thirdparty') {
accessforbidden('Partnership is not activated for thirdparties');
}
if (empty($conf->partnership->enabled)) {
accessforbidden();
}
if (empty($permissiontoread)) {
accessforbidden();
}
if ($action == 'edit' && empty($permissiontoadd)) {
accessforbidden();
}
if (($action == 'update' || $action == 'edit') && $object->status != $object::STATUS_DRAFT && !empty($user->socid)) {
accessforbidden();
}
// Security check
$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
/*
* Actions
*/
$parameters = array('socid' => $id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$date_start = dol_mktime(0, 0, 0, GETPOST('date_partnership_startmonth', 'int'), GETPOST('date_partnership_startday', 'int'), GETPOST('date_partnership_startyear', 'int'));
$date_end = dol_mktime(0, 0, 0, GETPOST('date_partnership_endmonth', 'int'), GETPOST('date_partnership_endday', 'int'), GETPOST('date_partnership_endyear', 'int'));
if (empty($reshook)) {
$error = 0;
$backtopage = DOL_URL_ROOT.'/partnership/partnership.php?id='.($id > 0 ? $id : '__ID__');
// Actions when linking object each other
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
}
$object->fields['fk_soc']['visible'] = 0;
if ($object->id > 0 && $object->status == $object::STATUS_REFUSED && empty($action)) {
$object->fields['reason_decline_or_cancel']['visible'] = 1;
}
$object->fields['note_public']['visible'] = 1;
/*
* View
*/
$form = new Form($db);
$formfile = new FormFile($db);
$title = $langs->trans("Partnership");
llxHeader('', $title);
$form = new Form($db);
if ($id > 0) {
$langs->load("companies");
$object = new Societe($db);
$result = $object->fetch($id);
if (isModEnabled('notification')) {
$langs->load("mails");
}
$head = societe_prepare_head($object);
print dol_get_fiche_head($head, 'partnership', $langs->trans("ThirdParty"), -1, 'company');
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">';
if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
}
if ($object->client) {
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
}
print '</td></tr>';
}
if ($object->fournisseur) {
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
}
print '</td>';
print '</tr>';
}
print '</table>';
print '</div>';
print dol_get_fiche_end();
} else {
dol_print_error('', 'Parameter id not defined');
}
// Part to show record
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
// Buttons for actions
if ($action != 'presend') {
print '<div class="tabsAction">'."\n";
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
// Show
if ($permissiontoadd) {
print dolGetButtonAction($langs->trans('AddPartnership'), '', 'default', DOL_URL_ROOT.'/partnership/partnership_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode(DOL_URL_ROOT.'/societe/partnership.php?id='.$object->id), '', $permissiontoadd);
}
}
print '</div>'."\n";
}
//$morehtmlright = 'partnership/partnership_card.php?action=create&backtopage=%2Fdolibarr%2Fhtdocs%2Fpartnership%2Fpartnership_list.php';
$morehtmlright = '';
print load_fiche_titre($langs->trans("PartnershipDedicatedToThisThirdParty", $langs->transnoentitiesnoconv("Partnership")), $morehtmlright, '');
$socid = $object->id;
// TODO Replace this card with a table of list of all partnerships.
$object = new Partnership($db);
$partnershipid = $object->fetch(0, '', 0, $socid);
if ($partnershipid > 0) {
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">'."\n";
// Common attributes
unset($object->fields['fk_soc']); // Hide field already shown in banner
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
$forcefieldid = 'socid';
$forceobjectid = $object->fk_soc;
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '</table>';
print '</div>';
}
}
// End of page
llxFooter();
$db->close();