From 22bc3b879b0570933f9e79170e4f43bd6e9bccfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 2 Mar 2021 22:21:34 +0100 Subject: [PATCH] new box replace --- htdocs/adherents/index.php | 68 ---------- .../box_members_subscriptions_by_year.php | 128 ++++++++++++++++-- htdocs/langs/en_US/boxes.lang | 1 + 3 files changed, 120 insertions(+), 77 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 72113767620..4faa9b894b1 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -237,74 +237,6 @@ if ($conf->use_javascript_ajax) { print '
'; -// List of subscription by year -$Total = array(); -$Number = array(); -$tot = 0; -$numb = 0; - -$sql = "SELECT c.subscription, c.dateadh as dateh"; -$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c"; -$sql .= " WHERE d.entity IN (".getEntity('adherent').")"; -$sql .= " AND d.rowid = c.fk_adherent"; - - -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) { - $objp = $db->fetch_object($result); - $year = dol_print_date($db->jdate($objp->dateh), "%Y"); - $Total[$year] = (isset($Total[$year]) ? $Total[$year] : 0) + $objp->subscription; - $Number[$year] = (isset($Number[$year]) ? $Number[$year] : 0) + 1; - $tot += $objp->subscription; - $numb += 1; - $i++; - } -} - -print '
'; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print "\n"; - -krsort($Total); -$i = 0; -foreach ($Total as $key => $value) { - if ($i >= 8) { - print ''; - print ""; - print ""; - print ""; - print ""; - print "\n"; - break; - } - print ''; - print ""; - print ""; - print ""; - print ""; - print "\n"; - $i++; -} - -// Total -print ''; -print ''; -print ""; -print '"; -print ""; -print "\n"; -print "
'.$langs->trans("Year").''.$langs->trans("Subscriptions").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").'
...
$key".$Number[$key]."".price($value)."".price(price2num($value / $Number[$key], 'MT'))."
'.$langs->trans("Total").'".$numb."'.price($tot)."".price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT'))."
"; -print "
\n"; - - print '
'; print '
'; diff --git a/htdocs/core/boxes/box_members_subscriptions_by_year.php b/htdocs/core/boxes/box_members_subscriptions_by_year.php index c16933c5d3c..55a11339c0f 100644 --- a/htdocs/core/boxes/box_members_subscriptions_by_year.php +++ b/htdocs/core/boxes/box_members_subscriptions_by_year.php @@ -24,7 +24,7 @@ * \brief Module to show box of members */ -include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; +include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; /** @@ -83,8 +83,8 @@ class box_members_subscriptions_by_year extends ModeleBoxes $this->max = $max; - include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; + include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; + require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php'; $memberstatic = new Adherent($this->db); $statictype = new AdherentType($this->db); @@ -93,20 +93,130 @@ class box_members_subscriptions_by_year extends ModeleBoxes if ($user->rights->adherent->lire) { $num = 0; $line = 0; - if (1) { + // List of subscription by year + $Total = array(); + $Number = array(); + $tot = 0; + $numb = 0; + + $sql = "SELECT c.subscription, c.dateadh as dateh"; + $sql .= " FROM " . MAIN_DB_PREFIX . "adherent as d, " . MAIN_DB_PREFIX . "subscription as c"; + $sql .= " WHERE d.entity IN (" . getEntity('adherent') . ")"; + $sql .= " AND d.rowid = c.fk_adherent"; + + + $result = $this->db->query($sql); + if ($result) { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) { + $objp = $this->db->fetch_object($result); + $year = dol_print_date($this->db->jdate($objp->dateh), "%Y"); + $Total[$year] = (isset($Total[$year]) ? $Total[$year] : 0) + $objp->subscription; + $Number[$year] = (isset($Number[$year]) ? $Number[$year] : 0) + 1; + $tot += $objp->subscription; + $numb += 1; + $i++; + } + + + $line = 0; + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_titre"', + 'text' => $langs->trans("Year"), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => $langs->trans("Subscriptions"), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => $langs->trans("AmountTotal"), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => $langs->trans("AmountAverage"), + ); + + $line++; + + krsort($Total); + $i = 0; + foreach ($Total as $key => $value) { + if ($i >= 8) { + // print ''; + // print "..."; + // print ""; + // print ""; + // print ""; + // print "\n"; + $this->info_box_contents[$line][] = array( + 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', + 'text' => '...', + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => '', + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => '', + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => '', + ); + $line++; + break; + } + $this->info_box_contents[$line][] = array( + 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', + 'text' => ''.$key.'', + 'asis' => 1, + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => $Number[$key], + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => price($value), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => price(price2num($value / $Number[$key], 'MT')), + ); + $line++; + } + if ($num == 0) { $this->info_box_contents[$line][0] = array( 'td' => 'class="center"', - 'text'=>$langs->trans("NoRecordedMembers"), + 'text' => $langs->trans("NoRecordedMembers"), + ); + } else { + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total"', + 'text' => $langs->trans("Total"), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total right"', + 'text' => $numb, + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total right"', + 'text' => price($tot), + ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="liste_total right"', + 'text' => price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT')), ); } - - $this->db->free($result); } else { $this->info_box_contents[0][0] = array( 'td' => '', - 'maxlength'=>500, - 'text' => ($this->db->error().' sql='.$sql), + 'maxlength' => 500, + 'text' => ($this->db->error() . ' sql=' . $sql), ); } } else { diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index b6bdda7100e..6e70999fd77 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -23,6 +23,7 @@ BoxFicheInter=Latest interventions BoxCurrentAccounts=Open accounts balance BoxTitleMemberNextBirthdays=Birthdays of this month (members) BoxTitleMembersByType=Members by type +BoxTitleMembersSubscriptionsByYear=Members Subscriptions by year BoxTitleLastRssInfos=Latest %s news from %s BoxTitleLastProducts=Products/Services: last %s modified BoxTitleProductsAlertStock=Products: stock alert