Debug mass actions of partnership module

This commit is contained in:
Laurent Destailleur 2021-11-07 16:51:18 +01:00
parent ed9806576a
commit 969fe16442
6 changed files with 69 additions and 23 deletions

View File

@ -1556,6 +1556,7 @@ if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm ==
}
}
// Approve for leave only
if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $confirm == 'yes')) && $permissiontoapprove) {
$db->begin();

View File

@ -58,6 +58,7 @@ ManagePartnership=Manage partnership
BacklinkNotFoundOnPartnerWebsite=Backlink not found on partner website
ConfirmClosePartnershipAsk=Are you sure you want to cancel this partnership?
PartnershipType=Partnership type
PartnershipRefApproved=Partnership %s approved
#
# Template Mail

View File

@ -67,7 +67,7 @@ class Partnership extends CommonObject
const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1; // Validate (no more draft)
const STATUS_ACCEPTED = 2; // Approved
const STATUS_APPROVED = 2; // Approved
const STATUS_REFUSED = 3; // Refused
const STATUS_CANCELED = 9;
@ -707,13 +707,13 @@ class Partnership extends CommonObject
}
/**
* Accept object
* Approve object
*
* @param User $user User making status change
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <=0 if OK, 0=Nothing done, >0 if KO
*/
public function accept($user, $notrigger = 0)
public function approve($user, $notrigger = 0)
{
global $conf, $langs;
@ -722,7 +722,7 @@ class Partnership extends CommonObject
$error = 0;
// Protection
if ($this->status == self::STATUS_ACCEPTED) {
if ($this->status == self::STATUS_APPROVED) {
dol_syslog(get_class($this)."::accept action abandonned: already acceptd", LOG_WARNING);
return 0;
}
@ -751,7 +751,7 @@ class Partnership extends CommonObject
// Accept
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET ref = '".$this->db->escape($num)."',";
$sql .= " status = ".self::STATUS_ACCEPTED;
$sql .= " status = ".self::STATUS_APPROVED;
// if (!empty($this->fields['date_validation'])) {
// $sql .= ", date_validation = '".$this->db->idate($now)."'";
// }
@ -818,7 +818,7 @@ class Partnership extends CommonObject
// Set new ref and current status
if (!$error) {
$this->ref = $num;
$this->status = self::STATUS_ACCEPTED;
$this->status = self::STATUS_APPROVED;
}
if (!$error) {
@ -893,7 +893,7 @@ class Partnership extends CommonObject
public function cancel($user, $notrigger = 0)
{
// Protection
if ($this->status != self::STATUS_ACCEPTED) {
if ($this->status != self::STATUS_APPROVED) {
return 0;
}
@ -928,7 +928,7 @@ class Partnership extends CommonObject
return -1;
}*/
return $this->setStatusCommon($user, self::STATUS_ACCEPTED, $notrigger, 'PARTNERSHIP_REOPEN');
return $this->setStatusCommon($user, self::STATUS_APPROVED, $notrigger, 'PARTNERSHIP_REOPEN');
}
/**
@ -1073,18 +1073,18 @@ class Partnership extends CommonObject
//$langs->load("partnership");
$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
$this->labelStatus[self::STATUS_ACCEPTED] = $langs->transnoentitiesnoconv('Accepted');
$this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
$this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
$this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
$this->labelStatusShort[self::STATUS_ACCEPTED] = $langs->transnoentitiesnoconv('Accepted');
$this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
$this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
$this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
}
$statusType = 'status'.$status;
if ($status == self::STATUS_ACCEPTED) {
if ($status == self::STATUS_APPROVED) {
$statusType = 'status4';
}
if ($status == self::STATUS_REFUSED) {

View File

@ -101,7 +101,7 @@ class PartnershipUtils
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as dty on (dty.rowid = d.fk_adherent_type)";
$sql .= " WHERE fk_member > 0";
$sql .= " AND (d.datefin < '".$this->db->idate($datetotest)."' AND dty.subscription = 1)";
$sql .= " AND p.status = ".((int) $partnership::STATUS_ACCEPTED); // Only accepted not yet canceled
$sql .= " AND p.status = ".((int) $partnership::STATUS_APPROVED); // Only accepted not yet canceled
$sql .= $this->db->order('d.rowid', 'ASC');
// Limit is managed into loop later
@ -262,7 +262,7 @@ class PartnershipUtils
$sql .= " WHERE 1 = 1";
$sql .= " AND p.".$fk_partner." > 0";
$sql .= " AND p.status = ".((int) $partnership::STATUS_ACCEPTED); // Only accepted not yet canceled
$sql .= " AND p.status = ".((int) $partnership::STATUS_APPROVED); // Only accepted not yet canceled
$sql .= " AND (p.last_check_backlink IS NULL OR p.last_check_backlink <= '".$this->db->idate($now - 7 * 24 * 3600)."')"; // Every week, check that website contains a link to dolibarr.
$sql .= $this->db->order('p.rowid', 'ASC');
// Limit is managed into loop later

View File

@ -153,7 +153,7 @@ if (empty($reshook)) {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif ($action == 'confirm_accept' && $confirm == 'yes' && $permissiontoadd) {
$result = $object->accept($user);
$result = $object->approve($user);
if ($result >= 0) {
// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
@ -590,9 +590,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Cancel
if ($permissiontoadd) {
if ($object->status == $object::STATUS_ACCEPTED) {
if ($object->status == $object::STATUS_APPROVED) {
print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
} elseif ($object->status > $object::STATUS_ACCEPTED) {
} elseif ($object->status > $object::STATUS_APPROVED) {
// print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken(), '', $permissiontoadd);
}
@ -600,7 +600,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Refuse
if ($permissiontoadd) {
if ($object->status != $object::STATUS_DRAFT && $object->status != $object::STATUS_ACCEPTED && $object->status != $object::STATUS_CANCELED && $object->status != $object::STATUS_REFUSED) {
if ($object->status != $object::STATUS_DRAFT && $object->status != $object::STATUS_APPROVED && $object->status != $object::STATUS_CANCELED && $object->status != $object::STATUS_REFUSED) {
print dolGetButtonAction($langs->trans('Refuse'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=refuse&token='.newToken(), '', $permissiontoadd);
}
}

View File

@ -29,8 +29,6 @@ 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.'/adherents/class/adherent.class.php';
// load partnership libraries
require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
// for other modules
@ -158,6 +156,8 @@ if ($user->socid > 0) { // Protection if external user
* Actions
*/
$error = 0;
if (GETPOST('cancel', 'alpha')) {
$action = 'list';
$massaction = '';
@ -200,6 +200,43 @@ if (empty($reshook)) {
$uploaddir = $conf->partnership->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
// Validate and approve
if (!$error && $massaction == 'approve' && $permissiontoadd) {
$objecttmp = new Partnership($db);
$db->begin();
$error = 0;
$result = 0;
foreach ($toselect as $checked) {
if ($objecttmp->fetch($checked)) {
if ($objecttmp->status == $objecttmp::STATUS_DRAFT) {
//$objecttmp->date = dol_now();
$result = $objecttmp->validate($user);
}
if ($result >= 0 && $objecttmp->status == $objecttmp::STATUS_VALIDATED) {
$result = $objecttmp->approve($user);
if ($result > 0) {
setEventMessages($langs->trans("PartnershipRefApproved", $objecttmp->ref), null);
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
}
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
}
}
}
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
// Cancel partnership
if ($massaction == 'cancel' && $permissiontoadd) {
$db->begin();
@ -208,9 +245,14 @@ if (empty($reshook)) {
$nbok = 0;
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
var_dump($objecttmp->status);
if ($result > 0) {
$result = $objecttmp->cancel($user, 3);
if ($result <= 0) {
$result = $objecttmp->cancel($user, 0);
var_dump($result);
if ($result == 0) {
setEventMessages($langs->trans('StatusOfRefMustBe', $objecttmp->ref, $objecttmp->LibStatut($objecttmp::STATUS_APPROVED)), null, 'warnings');
$error++;
} elseif ($result <= 0) {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
@ -432,7 +474,9 @@ $param .= $hookmanager->resPrint;
// List of mass actions available
$arrayofmassactions = array(
'cancel'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Cancel"),
//'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
'approve'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove"),
'cancel'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Cancel"),
//'generate_doc'=>img_picto('', 'pdf').$langs->trans("ReGeneratePDF"),
//'builddoc'=>img_picto('', 'pdf').$langs->trans("PDFMerge"),
'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendMail"),
@ -440,7 +484,7 @@ $arrayofmassactions = array(
if ($permissiontodelete) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('prevalidate', 'presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);