From 01e9d1bf4b3c29fb68a22de9f54d8434cdf34022 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 20 Dec 2022 18:38:01 +0100 Subject: [PATCH 01/24] NEW : Uniformize stat adh in boxes and index --- htdocs/adherents/class/adherent.class.php | 4 +- .../adherents/class/adherentstats.class.php | 53 +++++++ htdocs/adherents/index.php | 50 ++---- htdocs/core/boxes/box_members_by_type.php | 147 ++++++------------ 4 files changed, 119 insertions(+), 135 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 4c68b3e91ec..215e7de4bc2 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2381,8 +2381,8 @@ class Adherent extends CommonObject $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort"); } elseif (!$date_end_subscription) { $statusType = 'status1'; - $labelStatus = $langs->trans("MemberStatusActive"); - $labelStatusShort = $langs->trans("MemberStatusActiveShort"); + $labelStatus = $langs->trans("WaitingSubscription"); + $labelStatusShort = $langs->trans("WaitingSubscription"); } elseif ($date_end_subscription < dol_now()) { // expired $statusType = 'status8'; $labelStatus = $langs->trans("MemberStatusActiveLate"); diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 9aa2fe2e8ad..b2d856904fe 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -181,4 +181,57 @@ class AdherentStats extends Stats return $this->_getAllByYear($sql); } + + + /** + * Return count of member by status group by adh type, total and average + * + * @return array Array with + */ + public function countMembersByTypeAndStatus() + { + global $user; + + $now = dol_now(); + + $sql = "SELECT COALESCE(d.fk_adherent_type, 'total') as fk_adherent_type, t.libelle as label"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_DRAFT." THEN 'members_draft' ELSE NULL END) as members_draft"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1') THEN 'members_pending' ELSE NULL END) as members_pending"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0) THEN 'members_uptodate' ELSE NULL END) as members_uptodate"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1) THEN 'members_expired' ELSE NULL END) as members_expired"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_EXCLUDED." THEN 'members_excluded' ELSE NULL END) as members_excluded"; + $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_RESILIATED." THEN 'members_resiliated' ELSE NULL END) as members_resiliated"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d , ".MAIN_DB_PREFIX."adherent_type as t"; + $sql .= " WHERE t.rowid = d.fk_adherent_type"; + $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; + $sql .= " AND t.entity IN (".getEntity('member_type').")"; + $sql .= " AND t.statut = 1"; + $sql .= " GROUP BY d.fk_adherent_type"; + $sql .= " WITH ROLLUP;"; + + dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) { + $num = $this->db->num_rows($result); + $i = 0; + $MembersCountArray = []; + while ($i < $num) { + $objp = $this->db->fetch_object($result); + $MembersCountArray[$objp->fk_adherent_type] = array( + "label" => $objp->label, + "members_draft" => (int) $objp->members_draft, + "members_pending" => (int) $objp->members_pending, + "members_uptodate" => (int) $objp->members_uptodate, + "members_expired" => (int) $objp->members_expired, + "members_excluded" => (int) $objp->members_excluded, + "members_resiliated" => (int) $objp->members_resiliated + ); + $i++; + } + $this->db->free($result); + } + return $MembersCountArray; + } + } diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index a5f9c26f192..e6d069bc3e2 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -85,6 +85,7 @@ $subscriptionstatic = new Subscription($db); print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist'], 'members'); +/* $MembersValidated = array(); $MembersToValidate = array(); $MembersWaitingSubscription = array(); @@ -217,43 +218,24 @@ if ($conf->use_javascript_ajax) { $boxgraph .=''; $boxgraph .=''; $boxgraph .=''; $boxgraph .= ''; $boxgraph .= '
'.$langs->trans("Statistics").'
'; + + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; + $stats = new AdherentStats($db, 0, $userid); - $SumToValidate = 0; - $SumWaitingSubscription = 0; - $SumUpToDate = 0; - $SumExpired = 0; - $SumResiliated = 0; - $SumExcluded = 0; - - $total = 0; - $dataval = array(); - $i = 0; - foreach ($AdherentType as $key => $adhtype) { - $dataval['draft'][] = array($i, isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0); - $dataval['waitingsubscription'][] = array($i, isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0); - $dataval['uptodate'][] = array($i, isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0); - $dataval['expired'][] = array($i, isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0); - $dataval['excluded'][] = array($i, isset($MembersExcluded[$key]) ? $MembersExcluded[$key] : 0); - $dataval['resiliated'][] = array($i, isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0); - - $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0; - $SumWaitingSubscription += isset($MembersWaitingSubscription[$key]) ? $MembersWaitingSubscription[$key] : 0; - $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0; - $SumExpired += isset($MembersExpired[$key]) ? $MembersExpired[$key] : 0; - $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0; - $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0; - $i++; - } - $total = $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated; + // Show array + $sumMembers = $stats->countMembersByTypeAndStatus(); + $total = $sumMembers['total']['members_draft'] + $sumMembers['total']['members_pending'] + $sumMembers['total']['members_uptodate'] + $sumMembers['total']['members_expired'] + $sumMembers['total']['members_excluded'] + $sumMembers['total']['members_resiliated']; + $dataseries = array(); - $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), round($SumToValidate)); // Draft, not yet validated - $dataseries[] = array($langs->transnoentitiesnoconv("WaitingSubscription"), round($SumWaitingSubscription)); - $dataseries[] = array($langs->transnoentitiesnoconv("UpToDate"), round($SumUpToDate)); - $dataseries[] = array($langs->transnoentitiesnoconv("OutOfDate"), round($SumExpired)); - $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusExcluded"), round($SumExcluded)); - $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), round($SumResiliated)); + $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), $sumMembers['total']['members_draft']); // Draft, not yet validated + $dataseries[] = array($langs->transnoentitiesnoconv("WaitingSubscription"), $sumMembers['total']['members_pending']); + $dataseries[] = array($langs->transnoentitiesnoconv("UpToDate"), $sumMembers['total']['members_uptodate']); + $dataseries[] = array($langs->transnoentitiesnoconv("OutOfDate"), $sumMembers['total']['members_expired']); + $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusExcluded"), $sumMembers['total']['members_excluded']); + $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), $sumMembers['total']['members_resiliated']); include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; + echo "
";var_dump($total); echo "
"; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $dolgraph = new DolGraph(); @@ -268,7 +250,7 @@ if ($conf->use_javascript_ajax) { $boxgraph .= '
'.$langs->trans("Total").''; - $boxgraph .= $SumToValidate + $SumWaitingSubscription + $SumUpToDate + $SumExpired + $SumExcluded + $SumResiliated; + $boxgraph .= $total; $boxgraph .= '
'; $boxgraph .= ''; diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 2e25da59564..ef64053b9be 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -91,124 +91,64 @@ class box_members_by_type extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType", $max)); if ($user->rights->adherent->lire) { - $MembersToValidate = array(); - $MembersValidated = array(); - $MembersUpToDate = array(); - $MembersExcluded = array(); - $MembersResiliated = array(); - - $SumToValidate = 0; - $SumValidated = 0; - $SumUpToDate = 0; - $SumResiliated = 0; - $SumExcluded = 0; - - $AdherentType = array(); - - // Type of membership - $sql = "SELECT t.rowid, t.libelle as label, t.subscription,"; - $sql .= " d.statut, count(d.rowid) as somme"; - $sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type as t"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "adherent as d"; - $sql .= " ON t.rowid = d.fk_adherent_type"; - $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " WHERE t.entity IN (" . getEntity('member_type') . ")"; - $sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut"; - - dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) { - $objp = $this->db->fetch_object($result); - - $adhtype = new AdherentType($this->db); - $adhtype->id = $objp->rowid; - $adhtype->subscription = $objp->subscription; - $adhtype->label = $objp->label; - $AdherentType[$objp->rowid] = $adhtype; - - if ($objp->statut == Adherent::STATUS_DRAFT) { - $MembersToValidate[$objp->rowid] = $objp->somme; - } - if ($objp->statut == Adherent::STATUS_VALIDATED) { - $MembersValidated[$objp->rowid] = $objp->somme; - } - if ($objp->statut == Adherent::STATUS_EXCLUDED) { - $MembersExcluded[$objp->rowid] = $objp->somme; - } - if ($objp->statut == Adherent::STATUS_RESILIATED) { - $MembersResiliated[$objp->rowid] = $objp->somme; - } - - $i++; - } - $this->db->free($result); - $now = dol_now(); - - // Members up to date list - // current rule: uptodate = the end date is in future whatever is type - // old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future) - $sql = "SELECT count(*) as somme , d.fk_adherent_type"; - $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d, " . MAIN_DB_PREFIX . "adherent_type as t"; - $sql .= " WHERE d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND d.statut = 1 AND (d.datefin >= '" . $this->db->idate($now) . "' OR t.subscription = 0)"; - $sql .= " AND t.rowid = d.fk_adherent_type"; - $sql .= " GROUP BY d.fk_adherent_type"; - - dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $num2 = $this->db->num_rows($result); - $i = 0; - while ($i < $num2) { - $objp = $this->db->fetch_object($result); - $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme; - $i++; - } - $this->db->free($result); - } + + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; + $stats = new AdherentStats($this->db, $user->socid, $user->id); + // Show array + $sumMembers = $stats->countMembersByTypeAndStatus(); + if ($sumMembers) { $line = 0; $this->info_box_contents[$line][] = array( 'td' => 'class=""', 'text' => '', ); + // Members Status To Valid $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1); $this->info_box_contents[$line][] = array( 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); - $labelstatus = $langs->trans("UpToDate"); + // Waiting for subscription + $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'text' => $labelstatus, + ); + // Up to date $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() + 86400, 1); $this->info_box_contents[$line][] = array( 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus, ); - $labelstatus = $langs->trans("OutOfDate"); + // Out of date $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() - 86400, 1); $this->info_box_contents[$line][] = array( 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); + // Excluded $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1); $this->info_box_contents[$line][] = array( 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); + // Resiliated $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1); $this->info_box_contents[$line][] = array( 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); $line++; - foreach ($AdherentType as $key => $adhtype) { - $SumToValidate += isset($MembersToValidate[$key]) ? $MembersToValidate[$key] : 0; - $SumValidated += isset($MembersValidated[$key]) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : 0; - $SumUpToDate += isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0; - $SumExcluded += isset($MembersExcluded[$key]) ? $MembersExcluded [$key] : 0; - $SumResiliated += isset($MembersResiliated[$key]) ? $MembersResiliated[$key] : 0; + foreach ($sumMembers as $key => $data) { + $adhtype = new AdherentType($this->db); + $adhtype->id = $key; + + if($key=='total'){ + break; + } + $adhtype->label = $data['label']; + $AdherentType[$key] = $adhtype; $this->info_box_contents[$line][] = array( 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', @@ -217,36 +157,40 @@ class box_members_by_type extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($MembersToValidate[$key]) && $MembersToValidate[$key] > 0 ? $MembersToValidate[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3), + 'text' => (isset($data['members_draft']) && $data['members_draft'] > 0 ? $data['members_draft'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3), 'asis' => 1, ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($MembersUpToDate[$key]) && $MembersUpToDate[$key] > 0 ? $MembersUpToDate[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), + 'text' => (isset($data['members_pending']) && $data['members_pending'] > 0 ? $data['members_pending'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), 'asis' => 1, ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($MembersValidated[$key]) && ($MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) > 0) ? $MembersValidated[$key] - (isset($MembersUpToDate[$key]) ? $MembersUpToDate[$key] : 0) : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3), + 'text' => (isset($data['members_uptodate']) && $data['members_uptodate'] > 0 ? $data['members_uptodate'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3), 'asis' => 1, ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($MembersExcluded[$key]) && $MembersExcluded[$key] > 0 ? $MembersExcluded[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3), + 'text' => (isset($data['members_expired']) && $data['members_expired'] > 0 ? $data['members_expired'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3), 'asis' => 1, ); $this->info_box_contents[$line][] = array( 'td' => 'class="right"', - 'text' => (isset($MembersResiliated[$key]) && $MembersResiliated[$key] > 0 ? $MembersResiliated[$key] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), + 'text' => (isset($data['members_excluded']) && $data['members_excluded'] > 0 ? $data['members_excluded'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, $now, 3), + 'asis' => 1, + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), 'asis' => 1, ); - $line++; } - if ($num == 0) { + if (count($sumMembers) == 0) { $this->info_box_contents[$line][0] = array( - 'td' => 'class="center"', + 'td' => 'class="center" colspan="6"', 'text' => $langs->trans("NoRecordedMembersByType") ); } else { @@ -257,27 +201,32 @@ class box_members_by_type extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $SumToValidate.' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3), + 'text' => $sumMembers['total']['members_draft'].' '.$staticmember->LibStatut(Adherent::STATUS_DRAFT, 1, 0, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $SumUpToDate.' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), + 'text' => $sumMembers['total']['members_pending'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, $now, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $SumValidated.' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3), + 'text' => $sumMembers['total']['members_uptodate'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 0, 0, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $SumExcluded.' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3), + 'text' => $sumMembers['total']['members_expired'].' '.$staticmember->LibStatut(Adherent::STATUS_VALIDATED, 1, 1, 3), 'asis' => 1 ); $this->info_box_contents[$line][] = array( 'td' => 'class="liste_total right"', - 'text' => $SumResiliated.' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), + 'text' => $sumMembers['total']['members_excluded'].' '.$staticmember->LibStatut(Adherent::STATUS_EXCLUDED, 1, 0, 3), + 'asis' => 1 + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total right"', + 'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), 'asis' => 1 ); } From 300c58dd3835790e1ad5d93807e733b51512db37 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 20 Dec 2022 18:45:21 +0100 Subject: [PATCH 02/24] Clean code --- htdocs/adherents/index.php | 124 ------------------------------------- 1 file changed, 124 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index e6d069bc3e2..29a21f03fc7 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -85,129 +85,6 @@ $subscriptionstatic = new Subscription($db); print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist'], 'members'); -/* -$MembersValidated = array(); -$MembersToValidate = array(); -$MembersWaitingSubscription = array(); -$MembersUpToDate = array(); -$MembersExpired = array(); -$MembersExcluded = array(); -$MembersResiliated = array(); - -$AdherentType = array(); - -// Type of membership -$sql = "SELECT t.rowid, t.libelle as label, t.subscription,"; -$sql .= " d.statut, count(d.rowid) as somme"; -$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d"; -$sql .= " ON t.rowid = d.fk_adherent_type"; -$sql .= " AND d.entity IN (".getEntity('adherent').")"; -$sql .= " WHERE t.entity IN (".getEntity('member_type').")"; -$sql .= " GROUP BY t.rowid, t.libelle, t.subscription, d.statut"; - -dol_syslog("index.php::select nb of members per type", LOG_DEBUG); -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $objp = $db->fetch_object($resql); - - $adhtype = new AdherentType($db); - $adhtype->id = $objp->rowid; - $adhtype->subscription = $objp->subscription; - $adhtype->label = $objp->label; - $AdherentType[$objp->rowid] = $adhtype; - - if ($objp->statut == -1) { - $MembersToValidate[$objp->rowid] = $objp->somme; - } - if ($objp->statut == 1) { - $MembersValidated[$objp->rowid] = $objp->somme; - } - if ($objp->statut == -2) { - $MembersExcluded[$objp->rowid] = $objp->somme; - } - if ($objp->statut == 0) { - $MembersResiliated[$objp->rowid] = $objp->somme; - } - - $i++; - } - $db->free($resql); -} - -$now = dol_now(); - -// Members waiting subscription -$sql = "SELECT count(*) as somme , d.fk_adherent_type"; -$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t"; -$sql .= " WHERE d.entity IN (".getEntity('adherent').")"; -$sql .= " AND d.statut = 1"; // validated -$sql .= " AND (d.datefin IS NULL AND t.subscription = '1')"; -$sql .= " AND t.rowid = d.fk_adherent_type"; -$sql .= " GROUP BY d.fk_adherent_type"; - -dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG); -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $objp = $db->fetch_object($resql); - $MembersWaitingSubscription[$objp->fk_adherent_type] = $objp->somme; - $i++; - } - $db->free($resql); -} - -// Members up to date list -// current rule: uptodate = the end date is in future or no subcription required -// old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future) -$sql = "SELECT count(*) as somme , d.fk_adherent_type"; -$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t"; -$sql .= " WHERE d.entity IN (".getEntity('adherent').")"; -$sql .= " AND d.statut = 1"; // validated -$sql .= " AND (d.datefin >= '".$db->idate($now)."' OR t.subscription = '0')"; // end date in future -$sql .= " AND t.rowid = d.fk_adherent_type"; -$sql .= " GROUP BY d.fk_adherent_type"; - -dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG); -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $objp = $db->fetch_object($resql); - $MembersUpToDate[$objp->fk_adherent_type] = $objp->somme; - $i++; - } - $db->free($resql); -} - -// Members expired list -$sql = "SELECT count(*) as somme , d.fk_adherent_type"; -$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t"; -$sql .= " WHERE d.entity IN (".getEntity('adherent').")"; -$sql .= " AND d.statut = 1"; // validated -$sql .= " AND (d.datefin < '".$db->idate($now)."' AND t.subscription = '1')"; -$sql .= " AND t.rowid = d.fk_adherent_type"; -$sql .= " GROUP BY d.fk_adherent_type"; - -dol_syslog("index.php::select nb of uptodate members by type", LOG_DEBUG); -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $objp = $db->fetch_object($resql); - $MembersExpired[$objp->fk_adherent_type] = $objp->somme; - $i++; - } - $db->free($resql); -} - /* * Statistics */ @@ -235,7 +112,6 @@ if ($conf->use_javascript_ajax) { $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusResiliated"), $sumMembers['total']['members_resiliated']); include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; - echo "
";var_dump($total); echo "
"; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $dolgraph = new DolGraph(); From 21e22ee990876d46275a2a54893d24f2d97fffab Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 20 Dec 2022 18:06:23 +0000 Subject: [PATCH 03/24] Fixing style errors. --- htdocs/adherents/class/adherentstats.class.php | 7 +++---- htdocs/adherents/index.php | 4 ++-- htdocs/core/boxes/box_members_by_type.php | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index b2d856904fe..6e29f988ada 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -186,7 +186,7 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @return array Array with + * @return array Array with */ public function countMembersByTypeAndStatus() { @@ -208,10 +208,10 @@ class AdherentStats extends Stats $sql .= " AND t.statut = 1"; $sql .= " GROUP BY d.fk_adherent_type"; $sql .= " WITH ROLLUP;"; - + dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $num = $this->db->num_rows($result); $i = 0; @@ -233,5 +233,4 @@ class AdherentStats extends Stats } return $MembersCountArray; } - } diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 29a21f03fc7..823ea6edfce 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -95,14 +95,14 @@ if ($conf->use_javascript_ajax) { $boxgraph .=''; $boxgraph .=''; $boxgraph .='
'.$langs->trans("Statistics").'
'; - + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; $stats = new AdherentStats($db, 0, $userid); // Show array $sumMembers = $stats->countMembersByTypeAndStatus(); $total = $sumMembers['total']['members_draft'] + $sumMembers['total']['members_pending'] + $sumMembers['total']['members_uptodate'] + $sumMembers['total']['members_expired'] + $sumMembers['total']['members_excluded'] + $sumMembers['total']['members_resiliated']; - + $dataseries = array(); $dataseries[] = array($langs->transnoentitiesnoconv("MembersStatusToValid"), $sumMembers['total']['members_draft']); // Draft, not yet validated $dataseries[] = array($langs->transnoentitiesnoconv("WaitingSubscription"), $sumMembers['total']['members_pending']); diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index ef64053b9be..70be7f7a61e 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -91,13 +91,11 @@ class box_members_by_type extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType", $max)); if ($user->rights->adherent->lire) { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; $stats = new AdherentStats($this->db, $user->socid, $user->id); // Show array $sumMembers = $stats->countMembersByTypeAndStatus(); if ($sumMembers) { - $line = 0; $this->info_box_contents[$line][] = array( 'td' => 'class=""', @@ -144,7 +142,7 @@ class box_members_by_type extends ModeleBoxes $adhtype = new AdherentType($this->db); $adhtype->id = $key; - if($key=='total'){ + if ($key=='total') { break; } $adhtype->label = $data['label']; From f1f510cf60353a86b783eda38437ca1a62481906 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 20 Dec 2022 19:40:58 +0100 Subject: [PATCH 04/24] Copyright --- htdocs/adherents/class/adherentstats.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 6e29f988ada..3abc4fdcf49 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (c) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2022 Waël Almoman * * 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 From af95484b91ee1769450bb1a2d6cf7e5a1ccbe31b Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 20 Dec 2022 19:42:05 +0100 Subject: [PATCH 05/24] Copyright --- htdocs/adherents/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 823ea6edfce..8f67adb61d1 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2019 Nicolas ZABOURI * Copyright (C) 2021 Frédéric France - * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2021-2022 Waël Almoman * * 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 From 7c6543b52902d4f16f1a2b1c9f703dc7d12fbe4e Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 20 Dec 2022 19:43:22 +0100 Subject: [PATCH 06/24] Copyright --- htdocs/core/boxes/box_members_by_type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 70be7f7a61e..9c0acd521ae 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015-2020 Frederic France - * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2021-2022 Waël Almoman * * 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 From 4c47e29a2de2fd58e23f1fc398f75042a94731d5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Dec 2022 19:38:49 +0100 Subject: [PATCH 07/24] Update adherent.class.php --- htdocs/adherents/class/adherent.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 215e7de4bc2..4c68b3e91ec 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2381,8 +2381,8 @@ class Adherent extends CommonObject $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort"); } elseif (!$date_end_subscription) { $statusType = 'status1'; - $labelStatus = $langs->trans("WaitingSubscription"); - $labelStatusShort = $langs->trans("WaitingSubscription"); + $labelStatus = $langs->trans("MemberStatusActive"); + $labelStatusShort = $langs->trans("MemberStatusActiveShort"); } elseif ($date_end_subscription < dol_now()) { // expired $statusType = 'status8'; $labelStatus = $langs->trans("MemberStatusActiveLate"); From 0ae8809ae24496b32b479ca92a863b8ea9ea312b Mon Sep 17 00:00:00 2001 From: daraelmin Date: Thu, 22 Dec 2022 12:40:12 +0100 Subject: [PATCH 08/24] Use db->ifsql instead of case when --- htdocs/adherents/class/adherentstats.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 3abc4fdcf49..9aeb6a3ea46 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -196,12 +196,12 @@ class AdherentStats extends Stats $now = dol_now(); $sql = "SELECT COALESCE(d.fk_adherent_type, 'total') as fk_adherent_type, t.libelle as label"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_DRAFT." THEN 'members_draft' ELSE NULL END) as members_draft"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1') THEN 'members_pending' ELSE NULL END) as members_pending"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0) THEN 'members_uptodate' ELSE NULL END) as members_uptodate"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1) THEN 'members_expired' ELSE NULL END) as members_expired"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_EXCLUDED." THEN 'members_excluded' ELSE NULL END) as members_excluded"; - $sql .= ", COUNT(CASE WHEN d.statut = ".Adherent::STATUS_RESILIATED." THEN 'members_resiliated' ELSE NULL END) as members_resiliated"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)","'members_expired'", 'NULL').") as members_expired"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED,"'members_excluded'", 'NULL').") as members_excluded"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED,"'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d , ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " WHERE t.rowid = d.fk_adherent_type"; $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; From 0109a4e1728700c8da8763375c9dca3c5e0a2171 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 22 Dec 2022 11:40:52 +0000 Subject: [PATCH 09/24] Fixing style errors. --- htdocs/adherents/class/adherentstats.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 9aeb6a3ea46..0ca91273512 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -196,12 +196,12 @@ class AdherentStats extends Stats $now = dol_now(); $sql = "SELECT COALESCE(d.fk_adherent_type, 'total') as fk_adherent_type, t.libelle as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)","'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED,"'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED,"'members_resiliated'", 'NULL').") as members_resiliated"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d , ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " WHERE t.rowid = d.fk_adherent_type"; $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; From e16994bcff4a581a08c575f20fd26d64c85ffe54 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Thu, 22 Dec 2022 16:23:18 +0100 Subject: [PATCH 10/24] Fix add not used active member type --- htdocs/adherents/class/adherentstats.class.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 9aeb6a3ea46..c31cdd2284d 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -187,7 +187,7 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @return array Array with + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ public function countMembersByTypeAndStatus() { @@ -195,19 +195,18 @@ class AdherentStats extends Stats $now = dol_now(); - $sql = "SELECT COALESCE(d.fk_adherent_type, 'total') as fk_adherent_type, t.libelle as label"; + $sql = "SELECT COALESCE(t.rowid, 'total') as fk_adherent_type, t.libelle as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)","'members_expired'", 'NULL').") as members_expired"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED,"'members_excluded'", 'NULL').") as members_excluded"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED,"'members_resiliated'", 'NULL').") as members_resiliated"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d , ".MAIN_DB_PREFIX."adherent_type as t"; - $sql .= " WHERE t.rowid = d.fk_adherent_type"; - $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND t.entity IN (".getEntity('member_type').")"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; + $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; $sql .= " AND t.statut = 1"; - $sql .= " GROUP BY d.fk_adherent_type"; + $sql .= " GROUP BY t.rowid"; $sql .= " WITH ROLLUP;"; dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); From 64363066340123d3ce6748b6b020a0d8cf280b27 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 22 Dec 2022 15:25:09 +0000 Subject: [PATCH 11/24] Fixing style errors. --- htdocs/adherents/class/adherentstats.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index c31cdd2284d..53ad30bcd26 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -187,7 +187,7 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ public function countMembersByTypeAndStatus() { @@ -196,12 +196,12 @@ class AdherentStats extends Stats $now = dol_now(); $sql = "SELECT COALESCE(t.rowid, 'total') as fk_adherent_type, t.libelle as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)","'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED,"'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED,"'members_resiliated'", 'NULL').") as members_resiliated"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; From 26370ff1c81dafc6b29b5858d92cef3e3325e15f Mon Sep 17 00:00:00 2001 From: daraelmin Date: Thu, 22 Dec 2022 22:35:35 +0100 Subject: [PATCH 12/24] Remove With rollup --- .../adherents/class/adherentstats.class.php | 36 ++++++++++++++----- htdocs/core/boxes/box_members_by_type.php | 16 +++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index c31cdd2284d..f7381b17fba 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -195,7 +195,7 @@ class AdherentStats extends Stats $now = dol_now(); - $sql = "SELECT COALESCE(t.rowid, 'total') as fk_adherent_type, t.libelle as label"; + $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; @@ -207,7 +207,6 @@ class AdherentStats extends Stats $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; $sql .= " AND t.statut = 1"; $sql .= " GROUP BY t.rowid"; - $sql .= " WITH ROLLUP;"; dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); $result = $this->db->query($sql); @@ -216,20 +215,39 @@ class AdherentStats extends Stats $num = $this->db->num_rows($result); $i = 0; $MembersCountArray = []; + $totalstatus = array( + 'label' => 'Total', + 'members_draft' => 0, + 'members_pending' => 0, + 'members_uptodate' => 0, + 'members_expired' => 0, + 'members_excluded' => 0, + 'members_resiliated' => 0 + ); while ($i < $num) { $objp = $this->db->fetch_object($result); $MembersCountArray[$objp->fk_adherent_type] = array( - "label" => $objp->label, - "members_draft" => (int) $objp->members_draft, - "members_pending" => (int) $objp->members_pending, - "members_uptodate" => (int) $objp->members_uptodate, - "members_expired" => (int) $objp->members_expired, - "members_excluded" => (int) $objp->members_excluded, - "members_resiliated" => (int) $objp->members_resiliated + 'label' => $objp->label, + 'members_draft' => (int) $objp->members_draft, + 'members_pending' => (int) $objp->members_pending, + 'members_uptodate' => (int) $objp->members_uptodate, + 'members_expired' => (int) $objp->members_expired, + 'members_excluded' => (int) $objp->members_excluded, + 'members_resiliated' => (int) $objp->members_resiliated ); + $totalrow = 0; + foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { + if ($key!='label'){ + $totalrow += $nb; + $totalstatus[$key] += $nb; + } + } + $MembersCountArray[$objp->fk_adherent_type]['total_adhtype'] = $totalrow; $i++; } $this->db->free($result); + $MembersCountArray['total'] = $totalstatus; + $MembersCountArray['total']['all'] = array_sum($totalstatus); } return $MembersCountArray; } diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 9c0acd521ae..2109e650a07 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -137,6 +137,12 @@ class box_members_by_type extends ModeleBoxes 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); + // Total row + $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($langs->trans("Total")).'"', + 'text' => $langs->trans("Total") + ); $line++; foreach ($sumMembers as $key => $data) { $adhtype = new AdherentType($this->db); @@ -183,6 +189,11 @@ class box_members_by_type extends ModeleBoxes 'text' => (isset($data['members_resiliated']) && $data['members_resiliated'] > 0 ? $data['members_resiliated'] : '') . ' ' . $staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), 'asis' => 1, ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => (isset($data['total_adhtype']) && $data['total_adhtype'] > 0 ? $data['total_adhtype'] : ''), + 'asis' => 1, + ); $line++; } @@ -227,6 +238,11 @@ class box_members_by_type extends ModeleBoxes 'text' => $sumMembers['total']['members_resiliated'].' '.$staticmember->LibStatut(Adherent::STATUS_RESILIATED, 1, 0, 3), 'asis' => 1 ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total right"', + 'text' => $sumMembers['total']['all'], + 'asis' => 1 + ); } } else { $this->info_box_contents[0][0] = array( From be34e7d53a5f466515c4a4ed86d70b0e85ca4799 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 22 Dec 2022 21:53:30 +0000 Subject: [PATCH 13/24] Fixing style errors. --- htdocs/adherents/class/adherentstats.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 2095af178e6..1809ecdf982 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -196,12 +196,12 @@ class AdherentStats extends Stats $now = dol_now(); $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT,"'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')","'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)","'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)","'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED,"'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED,"'members_resiliated'", 'NULL').") as members_resiliated"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; @@ -237,12 +237,12 @@ class AdherentStats extends Stats ); $totalrow = 0; foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { - if ($key!='label'){ + if ($key!='label') { $totalrow += $nb; $totalstatus[$key] += $nb; } } - $MembersCountArray[$objp->fk_adherent_type]['total_adhtype'] = $totalrow; + $MembersCountArray[$objp->fk_adherent_type]['total_adhtype'] = $totalrow; $i++; } $this->db->free($result); From d107cc4c0cd7f2439d67e89b62ec83c359a34e59 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Thu, 22 Dec 2022 22:53:57 +0100 Subject: [PATCH 14/24] Fix label status --- htdocs/adherents/class/adherent.class.php | 4 ++-- htdocs/langs/en_US/members.lang | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 6aaac503060..20e3871b01d 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2417,8 +2417,8 @@ class Adherent extends CommonObject $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort"); } elseif (!$date_end_subscription) { $statusType = 'status1'; - $labelStatus = $langs->trans("MemberStatusActive"); - $labelStatusShort = $langs->trans("MemberStatusActiveShort"); + $labelStatus = $langs->trans("WaitingSubscription"); + $labelStatusShort = $langs->trans("WaitingSubscriptionShort"); } elseif ($date_end_subscription < dol_now()) { // expired $statusType = 'status8'; $labelStatus = $langs->trans("MemberStatusActiveLate"); diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index eb911c1cdbf..4d91099a81a 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -37,6 +37,7 @@ EndSubscription=End of membership SubscriptionId=Contribution ID WithoutSubscription=Without membership WaitingSubscription=Membership pending +WaitingSubscriptionShort=Pending MemberId=Member Id MemberRef=Member Ref NewMember=New member From 0506f028c9b1417af9ec1f0ab1c4ff78b0be3992 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Fri, 23 Dec 2022 14:21:23 +0100 Subject: [PATCH 15/24] Add MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH in widget and graphh --- htdocs/adherents/class/adherentstats.class.php | 6 +++++- htdocs/adherents/index.php | 3 ++- htdocs/core/boxes/box_members_by_type.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 1809ecdf982..2af18e3e139 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -189,11 +189,14 @@ class AdherentStats extends Stats * * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ - public function countMembersByTypeAndStatus() + public function countMembersByTypeAndStatus($numberYears) { global $user; $now = dol_now(); + $endYear = date('Y'); + $startYear = $endYear - $numberYears; + echo "startYear = endYear - numberYears => $startYear = $endYear - $numberYears"; $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; @@ -204,6 +207,7 @@ class AdherentStats extends Stats $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; + $sql .= " AND d.datefin BETWEEN '".$this->db->idate(dol_get_first_day($startYear))."' AND '".$this->db->idate(dol_get_last_day($endYear))."'"; $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; $sql .= " AND t.statut = 1"; $sql .= " GROUP BY t.rowid"; diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 8f67adb61d1..d3178ee3df3 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -100,7 +100,8 @@ if ($conf->use_javascript_ajax) { $stats = new AdherentStats($db, 0, $userid); // Show array - $sumMembers = $stats->countMembersByTypeAndStatus(); + $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); + $sumMembers = $stats->countMembersByTypeAndStatus($numberyears); $total = $sumMembers['total']['members_draft'] + $sumMembers['total']['members_pending'] + $sumMembers['total']['members_uptodate'] + $sumMembers['total']['members_expired'] + $sumMembers['total']['members_excluded'] + $sumMembers['total']['members_resiliated']; $dataseries = array(); diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 903e5f6e686..17984f6d4e6 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -94,7 +94,8 @@ class box_members_by_type extends ModeleBoxes require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; $stats = new AdherentStats($this->db, $user->socid, $user->id); // Show array - $sumMembers = $stats->countMembersByTypeAndStatus(); + $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); + $sumMembers = $stats->countMembersByTypeAndStatus($numberyears); if ($sumMembers) { $line = 0; $this->info_box_contents[$line][] = array( From b1e5c92455efba490bdf60557feb2ae3d51fbbcc Mon Sep 17 00:00:00 2001 From: daraelmin Date: Fri, 23 Dec 2022 14:22:07 +0100 Subject: [PATCH 16/24] Clean code --- htdocs/adherents/class/adherentstats.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 2af18e3e139..4d03194766d 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -196,7 +196,6 @@ class AdherentStats extends Stats $now = dol_now(); $endYear = date('Y'); $startYear = $endYear - $numberYears; - echo "startYear = endYear - numberYears => $startYear = $endYear - $numberYears"; $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; From 61536455c2754d3e473dc408d71c3249ca5b95b6 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Fri, 23 Dec 2022 14:25:52 +0100 Subject: [PATCH 17/24] Comment --- htdocs/adherents/class/adherentstats.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 4d03194766d..be48b5c0b25 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -187,7 +187,8 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type + * @param int $numberYears Years to scan + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ public function countMembersByTypeAndStatus($numberYears) { From 9039bdb827164468eecc3dc6eacaf0ef2b73c818 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Fri, 23 Dec 2022 14:48:00 +0100 Subject: [PATCH 18/24] Add period in title --- htdocs/adherents/index.php | 6 ++++-- htdocs/core/boxes/box_members_by_type.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index d3178ee3df3..cb61d66b90d 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -91,16 +91,18 @@ print load_fiche_titre($langs->trans("MembersArea"), $resultboxes['selectboxlist $boxgraph = ''; if ($conf->use_javascript_ajax) { + $year = date('Y'); + $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); + $boxgraph .='
'; $boxgraph .=''; - $boxgraph .=''; + $boxgraph .=''; $boxgraph .='
'.$langs->trans("Statistics").'
'.$langs->trans("Statistics").' ('.$year-$numberyears.' - '.$year.')
'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; $stats = new AdherentStats($db, 0, $userid); // Show array - $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); $sumMembers = $stats->countMembersByTypeAndStatus($numberyears); $total = $sumMembers['total']['members_draft'] + $sumMembers['total']['members_pending'] + $sumMembers['total']['members_uptodate'] + $sumMembers['total']['members_expired'] + $sumMembers['total']['members_excluded'] + $sumMembers['total']['members_resiliated']; diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 17984f6d4e6..1fc6590fd99 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -88,13 +88,15 @@ class box_members_by_type extends ModeleBoxes require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php'; $staticmember = new Adherent($this->db); - $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType", $max)); + $year = date('Y'); + $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); + + $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType").' ('.$year-$numberyears.' - '.$year.')'); if ($user->rights->adherent->lire) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherentstats.class.php'; $stats = new AdherentStats($this->db, $user->socid, $user->id); // Show array - $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); $sumMembers = $stats->countMembersByTypeAndStatus($numberyears); if ($sumMembers) { $line = 0; From 1a2cf76e1c86e3013f9302bee9f378295ade2277 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 23 Dec 2022 13:48:33 +0000 Subject: [PATCH 19/24] Fixing style errors. --- htdocs/core/boxes/box_members_by_type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 1fc6590fd99..bed04be18b7 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -90,7 +90,7 @@ class box_members_by_type extends ModeleBoxes $year = date('Y'); $numberyears = empty(getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH")) ? 2 : getDolGlobalInt("MAIN_NB_OF_YEAR_IN_WIDGET_GRAPH"); - + $this->info_box_head = array('text' => $langs->trans("BoxTitleMembersByType").' ('.$year-$numberyears.' - '.$year.')'); if ($user->rights->adherent->lire) { From 4a49bc29060072d17e9206021f8507f0c9c3e955 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Fri, 23 Dec 2022 14:55:09 +0100 Subject: [PATCH 20/24] look and feel --- htdocs/core/boxes/box_members_by_type.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index 1fc6590fd99..ea475fbd15b 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -107,37 +107,37 @@ class box_members_by_type extends ModeleBoxes // Members Status To Valid $labelstatus = $staticmember->LibStatut($staticmember::STATUS_DRAFT, 0, 0, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); // Waiting for subscription $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, 0, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus, ); // Up to date $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() + 86400, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus, ); // Expired $labelstatus = $staticmember->LibStatut($staticmember::STATUS_VALIDATED, 1, dol_now() - 86400, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); // Excluded $labelstatus = $staticmember->LibStatut($staticmember::STATUS_EXCLUDED, 0, 0, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); // Resiliated $labelstatus = $staticmember->LibStatut($staticmember::STATUS_RESILIATED, 0, 0, 1); $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax100" width="15%" title="'.dol_escape_htmltag($labelstatus).'"', + 'td' => 'class="right tdoverflowmax100" width="10%" title="'.dol_escape_htmltag($labelstatus).'"', 'text' => $labelstatus ); // Total row From 95cea254e5777190e3ba489753eb06547a867f98 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Mon, 26 Dec 2022 22:39:17 +0100 Subject: [PATCH 21/24] Fix missing few up to date members --- htdocs/adherents/class/adherentstats.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index be48b5c0b25..683a18c7d62 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -207,7 +207,7 @@ class AdherentStats extends Stats $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND d.datefin BETWEEN '".$this->db->idate(dol_get_first_day($startYear))."' AND '".$this->db->idate(dol_get_last_day($endYear))."'"; + $sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'"; $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; $sql .= " AND t.statut = 1"; $sql .= " GROUP BY t.rowid"; From a67330a0ffad65cb58f2963333d10551a3fffd9a Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 14 May 2023 15:59:23 +0200 Subject: [PATCH 22/24] fix merge --- .../adherents/class/adherentstats.class.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 30c7aff0283..ad06058c054 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -173,7 +173,77 @@ class AdherentStats extends Stats return $this->_getAllByYear($sql); } + /** + * Return count of member by status group by adh type, total and average + * + * @param int $numberYears Years to scan + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type + */ + public function countMembersByTypeAndStatus($numberYears) + { + global $user; + $now = dol_now(); + $endYear = date('Y'); + $startYear = $endYear - $numberYears; + + $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; + $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; + $sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'"; + $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; + $sql .= " AND t.statut = 1"; + $sql .= " GROUP BY t.rowid"; + + dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) { + $num = $this->db->num_rows($result); + $i = 0; + $MembersCountArray = []; + $totalstatus = array( + 'label' => 'Total', + 'members_draft' => 0, + 'members_pending' => 0, + 'members_uptodate' => 0, + 'members_expired' => 0, + 'members_excluded' => 0, + 'members_resiliated' => 0 + ); + while ($i < $num) { + $objp = $this->db->fetch_object($result); + $MembersCountArray[$objp->fk_adherent_type] = array( + 'label' => $objp->label, + 'members_draft' => (int) $objp->members_draft, + 'members_pending' => (int) $objp->members_pending, + 'members_uptodate' => (int) $objp->members_uptodate, + 'members_expired' => (int) $objp->members_expired, + 'members_excluded' => (int) $objp->members_excluded, + 'members_resiliated' => (int) $objp->members_resiliated + ); + $totalrow = 0; + foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { + if ($key!='label') { + $totalrow += $nb; + $totalstatus[$key] += $nb; + } + } + $MembersCountArray[$objp->fk_adherent_type]['total_adhtype'] = $totalrow; + $i++; + } + $this->db->free($result); + $MembersCountArray['total'] = $totalstatus; + $MembersCountArray['total']['all'] = array_sum($totalstatus); + } + return $MembersCountArray; + } /** * Return count of member by status group by adh type, total and average From 873f1bc8e8ac33cd4d9c17cc0fa02eae257119ca Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 14 May 2023 16:53:12 +0200 Subject: [PATCH 23/24] remove new feature Must wait for an other PR --- .../adherents/class/adherentstats.class.php | 76 ------------------- 1 file changed, 76 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index ad06058c054..6f5ed0df082 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -244,80 +244,4 @@ class AdherentStats extends Stats } return $MembersCountArray; } - - /** - * Return count of member by status group by adh type, total and average - * - * @param int $numberYears Years to scan - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag - */ - public function countMembersByTagAndStatus($numberYears = 2) - { - global $user; - - $now = dol_now(); - $endYear = date('Y'); - $startYear = $endYear - $numberYears; - - $sql = "SELECT c.rowid as fk_categorie, c.label as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; - $sql .= " FROM ".MAIN_DB_PREFIX."categorie as c"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as ct ON c.rowid = ct.fk_categorie"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON d.rowid = ct.fk_member"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as t ON t.rowid = d.fk_adherent_type"; - $sql .= " WHERE c.entity IN (".getEntity('member_type').")"; - $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND t.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'"; - $sql .= " AND c.fk_parent = 0"; - $sql .= " GROUP BY c.rowid"; - - dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - $i = 0; - $MembersCountArray = []; - $totalstatus = array( - 'label' => 'Total', - 'members_draft' => 0, - 'members_pending' => 0, - 'members_uptodate' => 0, - 'members_expired' => 0, - 'members_excluded' => 0, - 'members_resiliated' => 0 - ); - while ($i < $num) { - $objp = $this->db->fetch_object($result); - $MembersCountArray[$objp->fk_categorie] = array( - 'label' => $objp->label, - 'members_draft' => (int) $objp->members_draft, - 'members_pending' => (int) $objp->members_pending, - 'members_uptodate' => (int) $objp->members_uptodate, - 'members_expired' => (int) $objp->members_expired, - 'members_excluded' => (int) $objp->members_excluded, - 'members_resiliated' => (int) $objp->members_resiliated - ); - $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_categorie] as $key=>$nb) { - if ($key!='label') { - $totalrow += $nb; - $totalstatus[$key] += $nb; - } - } - $MembersCountArray[$objp->fk_categorie]['total_adhtype'] = $totalrow; - $i++; - } - $this->db->free($result); - $MembersCountArray['total'] = $totalstatus; - $MembersCountArray['total']['all'] = array_sum($totalstatus); - } - return $MembersCountArray; - } } From 6abf459da57a2fb0960c12bb31e8850456789c79 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 14 May 2023 16:57:44 +0200 Subject: [PATCH 24/24] Fix copyright --- htdocs/adherents/class/adherentstats.class.php | 2 +- htdocs/adherents/index.php | 2 +- htdocs/core/boxes/box_members_by_type.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 6f5ed0df082..99111747fa9 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (c) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2022 Waël Almoman + * Copyright (C) 2023 Waël Almoman * * 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 diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 0cb1b060766..92b2cfe1425 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2019 Nicolas ZABOURI * Copyright (C) 2021 Frédéric France - * Copyright (C) 2021-2022 Waël Almoman + * Copyright (C) 2021-2023 Waël Almoman * * 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 diff --git a/htdocs/core/boxes/box_members_by_type.php b/htdocs/core/boxes/box_members_by_type.php index dd533ae64ae..4825897ed52 100644 --- a/htdocs/core/boxes/box_members_by_type.php +++ b/htdocs/core/boxes/box_members_by_type.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015-2020 Frederic France - * Copyright (C) 2021-2022 Waël Almoman + * Copyright (C) 2021-2023 Waël Almoman * * 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