diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 13cb7126769..f111f4f55e2 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -90,6 +90,9 @@ if (!$error && $massaction == 'confirm_presend') { if ($objecttmp->element == 'expensereport') { $thirdparty = new User($db); } + if ($objecttmp->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') { + $thirdparty = new Adherent($db); + } if ($objecttmp->element == 'holiday') { $thirdparty = new User($db); } @@ -107,6 +110,9 @@ if (!$error && $massaction == 'confirm_presend') { if ($objecttmp->element == 'expensereport') { $thirdpartyid = $objecttmp->fk_user_author; } + if ($objecttmp->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') { + $thirdpartyid = $objecttmp->fk_member; + } if ($objecttmp->element == 'holiday') { $thirdpartyid = $objecttmp->fk_user; } @@ -250,6 +256,10 @@ if (!$error && $massaction == 'confirm_presend') { $fuser = new User($db); $fuser->fetch($objectobj->fk_user_author); $sendto = $fuser->email; + } elseif ($objectobj->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') { + $fadherent = new Adherent($db); + $fadherent->fetch($objectobj->fk_member); + $sendto = $fadherent->email; } elseif ($objectobj->element == 'holiday') { $fuser = new User($db); $fuser->fetch($objectobj->fk_user); diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index de10465a736..62aafc2fdb5 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -151,6 +151,10 @@ if ($action == 'presend') { $fuser = new User($db); $fuser->fetch($object->fk_user_author); $liste['thirdparty'] = $fuser->getFullName($outputlangs)." <".$fuser->email.">"; + } elseif ($object->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') { + $fadherent = new Adherent($db); + $fadherent->fetch($object->fk_member); + $liste['member'] = $fadherent->getFullName($outputlangs)." <".$fadherent->email.">"; } elseif ($object->element == 'societe') { foreach ($object->thirdparty_and_contact_email_array(1) as $key => $value) { $liste[$key] = $value; diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 79b00f01590..2848bd3d48c 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -127,6 +127,10 @@ if ($massaction == 'presend') { $fuser = new User($db); $fuser->fetch($thirdpartyid); $liste['thirdparty'] = $fuser->getFullName($langs)." <".$fuser->email.">"; + } elseif ($objecttmp->element == 'partnership' && $conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') { + $fadherent = new Adherent($db); + $fadherent->fetch($objecttmp->fk_member); + $liste['member'] = $fadherent->getFullName($langs)." <".$fadherent->email.">"; } else { $soc = new Societe($db); $soc->fetch($thirdpartyid); diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 9b97aa475cf..18714962058 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -411,7 +411,10 @@ create table llx_partnership_extrafields ALTER TABLE llx_partnership_extrafields ADD INDEX idx_partnership_fk_object(fk_object); -INSERT INTO llx_c_email_templates (entity,module,type_template,label,lang,position,topic,joinfiles,content) VALUES (0, 'partnership', 'member', '(AlertStatusPartnershipExpiration)', NULL, 100, '[__[MAIN_INFO_SOCIETE_NOM]__] - __(YourMembershipWillSoonExpireTopic)__', 0, '\n

Dear __MEMBER_FULLNAME__,

\n__(YourMembershipWillSoonExpireContent)__

\n
\n\n __(Sincerely)__
\n __[PARTNERSHIP_SOCIETE_NOM]__
\n \n'); +INSERT INTO llx_c_email_templates (entity,module,type_template,label,lang,position,topic,joinfiles,content) VALUES (0, 'partnership', 'partnership_send', '(SendingEmailOnPartnershipWillExpire)', NULL, 100, '[__[MAIN_INFO_SOCIETE_NOM]__] - __(YourPartnershipWillSoonExpireTopic)__', 0, '\n

Hello,

\n__(YourPartnershipWillSoonExpireContent)__

\n
\n\n
\n\n __(Sincerely)__
\n __[MAIN_INFO_SOCIETE_NOM]__
\n \n'); +INSERT INTO llx_c_email_templates (entity,module,type_template,label,lang,position,topic,joinfiles,content) VALUES (0, 'partnership', 'partnership_send', '(SendingEmailOnPartnershipRefused)', NULL, 100, '[__[MAIN_INFO_SOCIETE_NOM]__] - __(YourPartnershipRefusedTopic)__', 0, '\n

Hello,

\n__(YourPartnershipRefusedContent)__

\n
\n\n
\n\n __(Sincerely)__
\n __[MAIN_INFO_SOCIETE_NOM]__
\n \n'); +INSERT INTO llx_c_email_templates (entity,module,type_template,label,lang,position,topic,joinfiles,content) VALUES (0, 'partnership', 'partnership_send', '(SendingEmailOnPartnershipCanceled)', NULL, 100, '[__[MAIN_INFO_SOCIETE_NOM]__] - __(YourPartnershipCanceledTopic)__', 0, '\n

Hello,

\n__(YourPartnershipCanceledContent)__

\n
\n\n
\n\n __(Sincerely)__
\n __[MAIN_INFO_SOCIETE_NOM]__
\n \n'); +ALTER TABLE llx_adherent ADD COLUMN website varchar(255) NULL AFTER email; ALTER TABLE llx_facture_fourn ADD COLUMN date_closing datetime DEFAULT NULL after date_valid; ALTER TABLE llx_facture_fourn ADD COLUMN fk_user_closing integer DEFAULT NULL after fk_user_valid; diff --git a/htdocs/langs/en_US/partnership.lang b/htdocs/langs/en_US/partnership.lang index 3848ffca987..758a44546fb 100644 --- a/htdocs/langs/en_US/partnership.lang +++ b/htdocs/langs/en_US/partnership.lang @@ -16,23 +16,23 @@ # # Generic # -ModulePartnershipName = Partnership management -PartnershipDescription = Module Partnership management +ModulePartnershipName=Partnership management +PartnershipDescription=Module Partnership management PartnershipDescriptionLong= Module Partnership management # # Menu # -NewPartnership = New Partnership -ListOfPartnerships = List of partnership +NewPartnership=New Partnership +ListOfPartnerships=List of partnership # # Admin page # -PartnershipSetup = Partnership setup -PartnershipAbout = About Partnership -PartnershipAboutPage = Partnership about page -PartnershipManagedFor = Partnership managed for +PartnershipSetup=Partnership setup +PartnershipAbout=About Partnership +PartnershipAboutPage=Partnership about page +PartnershipManagedFor=Partnership managed for # # Object @@ -44,12 +44,22 @@ DatePartnershipEnd=End date # # Template Mail # +SendingEmailOnPartnershipWillExpire=Partnership will expire +SendingEmailOnPartnershipRefused=Partnership refused +SendingEmailOnPartnershipCanceled=Partnership canceled +YourPartnershipWillSoonExpireTopic=Partnership expiration +YourPartnershipRefusedTopic=Partnership refused +YourPartnershipCanceledTopic=Partnership canceled + +YourPartnershipWillSoonExpireContent=We inform you that your partnership will soon expire. +YourPartnershipRefusedContent=We inform you that your partnership request has been refused. +YourPartnershipCanceledContent=We inform you that your partnership has been canceled. # # Status # -PartnershipDraft = Draft -PartnershipAccepted = Accepted -PartnershipRefused = Refused -PartnershipCanceled = Canceled \ No newline at end of file +PartnershipDraft=Draft +PartnershipAccepted=Accepted +PartnershipRefused=Refused +PartnershipCanceled=Canceled \ No newline at end of file diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 395a3893b7d..54a878f4e1f 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -169,14 +169,9 @@ class Partnership extends CommonObject $this->db = $db; - $fk_soc_visible = ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') ? 0 : 1; - $fk_member_visible = ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') ? 1 : 0; - $this->fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"), - 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>$fk_soc_visible, 'index'=>1,), - 'fk_member' => array('type'=>'integer:Adherent:adherents/class/adherent.class.php:1', 'label'=>'Member', 'enabled'=>'1', 'position'=>51, 'notnull'=>-1, 'visible'=>$fk_member_visible, 'index'=>1,), 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1), 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,), 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,), @@ -187,13 +182,19 @@ class Partnership extends CommonObject 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,), 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,), - 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>0, 'visible'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Accepté', '2'=>'Refusé', '9'=>'Annulé'),), 'date_partnership_start' => array('type'=>'date', 'label'=>'DatePartnershipStart', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>1,), 'date_partnership_end' => array('type'=>'date', 'label'=>'DatePartnershipEnd', 'enabled'=>'1', 'position'=>53, 'notnull'=>1, 'visible'=>1,), + 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>54, 'notnull'=>0, 'visible'=>2, 'index'=>1, 'arrayofkeyval'=>array('-1'=>'','0'=>$langs->trans('Draft'), '1'=>$langs->trans('Accepted'), '2'=>$langs->trans('Refused'), '9'=>$langs->trans('Canceled')),), 'count_last_url_check_error' => array('type'=>'integer', 'label'=>'CountLastUrlCheckError', 'enabled'=>'1', 'position'=>63, 'notnull'=>0, 'visible'=>-2, 'default'=>'0',), 'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>64, 'notnull'=>0, 'visible'=>-2,), ); + if($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member'){ + $this->fields['fk_member'] = array('type'=>'integer:Adherent:adherents/class/adherent.class.php:1', 'label'=>'Member', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1,); + } else { + $this->fields['fk_soc'] = array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1,); + } + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) { $this->fields['rowid']['visible'] = 0; } diff --git a/htdocs/partnership/partnership_card.php b/htdocs/partnership/partnership_card.php index c44174af52c..cb082dc640d 100644 --- a/htdocs/partnership/partnership_card.php +++ b/htdocs/partnership/partnership_card.php @@ -123,21 +123,18 @@ if (empty($action) && empty($id) && empty($ref)) { 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 -$upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1]; - -// Security check - Protection if external user -//if ($user->socid > 0) accessforbidden(); -//if ($user->socid > 0) $socid = $user->socid; -//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); -//restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', $isdraft); -//if (empty($conf->partnership->enabled)) accessforbidden(); -//if (empty($permissiontoread)) accessforbidden(); +$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 +$upload_dir = $conf->partnership->multidir_output[isset($object->entity) ? $object->entity : 1]; +$managedfor = $conf->global->PARTNERSHIP_IS_MANAGED_FOR; +if (empty($conf->partnership->enabled)) accessforbidden(); +if (empty($permissiontoread)) accessforbidden(); +if ($object->id > 0 && $object->fk_member > 0 && $managedfor != 'member') accessforbidden(); +if ($object->id > 0 && $object->fk_soc > 0 && $managedfor != 'thirdparty') accessforbidden(); /* * Actions @@ -502,6 +499,32 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea //unset($object->fields['fk_soc']); // Hide field already shown in banner include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; + // End of subscription date + if ($managedfor == 'member') { + $fadherent = new Adherent($db); + $fadherent->fetch($object->fk_member); + print ''.$langs->trans("SubscriptionEndDate").''; + if ($fadherent->datefin) { + print dol_print_date($fadherent->datefin, 'day'); + if ($fadherent->hasDelay()) { + print " ".img_warning($langs->trans("Late")); + } + } else { + if (!$adht->subscription) { + print $langs->trans("SubscriptionNotRecorded"); + if ($fadherent->statut > 0) { + print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled + } + } else { + print $langs->trans("SubscriptionNotReceived"); + if ($fadherent->statut > 0) { + print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled + } + } + } + print ''; + } + // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; @@ -669,7 +692,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } // Presend form - $modelmail = 'partnership'; + $modelmail = 'partnership_send'; $defaulttopic = 'InformationMessage'; $diroutput = $conf->partnership->dir_output; $trackid = 'partnership'.$object->id; diff --git a/htdocs/partnership/partnership_list.php b/htdocs/partnership/partnership_list.php index 8cd0cf79fd7..d5c28ee9a72 100644 --- a/htdocs/partnership/partnership_list.php +++ b/htdocs/partnership/partnership_list.php @@ -86,7 +86,7 @@ require_once __DIR__.'/class/partnership.class.php'; //dol_include_once('/othermodule/class/otherobject.class.php'); // Load translation files required by the page -$langs->loadLangs(array("partnership@partnership", "other")); +$langs->loadLangs(array("partnership", "members", "other")); $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) @@ -185,8 +185,8 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); -$permissiontoread = $user->rights->partnership->read; -$permissiontoadd = $user->rights->partnership->write; +$permissiontoread = $user->rights->partnership->read; +$permissiontoadd = $user->rights->partnership->write; $permissiontodelete = $user->rights->partnership->delete; // Security check @@ -248,6 +248,38 @@ if (empty($reshook)) { $objectlabel = 'Partnership'; $uploaddir = $conf->partnership->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + // Cancel partnership + if ($massaction == 'cancel' && $permissiontoadd) { + $db->begin(); + + $objecttmp = new $objectclass($db); + $nbok = 0; + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + $result = $objecttmp->cancel($user, 3); + if ($result <= 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else { + $nbok++; + } + } else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (!$error) { + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + $db->commit(); + } else { + $db->rollback(); + } + } } @@ -466,7 +498,7 @@ $arrayofmassactions = array( 'cancel'=>$langs->trans("Cancel"), //'generate_doc'=>$langs->trans("ReGeneratePDF"), //'builddoc'=>$langs->trans("PDFMerge"), - 'presend'=>$langs->trans("SendByMail"), + 'presend'=>$langs->trans("SendMail"), ); if ($permissiontodelete) { $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); @@ -493,9 +525,9 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sort // Add code for pre mass action (confirmation or email presend form) $topicmail = "SendPartnershipRef"; -$modelmail = "partnership"; +$modelmail = "partnership_send"; $objecttmp = new Partnership($db); -$trackid = 'xxxx'.$object->id; +$trackid = 'partnership'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; if ($search_all) { @@ -742,6 +774,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { $i++; } +$totalarray['nbfield']++; // End of subscription date // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; @@ -754,6 +787,7 @@ if ($num == 0) { $colspan++; } } + $colspan++; // End of subscription date print ''.$langs->trans("NoRecordFound").''; }