NEW add api for members statistics (#35851)

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* NEW add api for members statistics

* fix

* fix

* fix

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE
2025-10-21 02:05:51 +02:00
committed by GitHub
parent 8b47aadb1c
commit cd3b74f092
8 changed files with 111 additions and 17 deletions

1
.gitignore vendored
View File

@@ -52,6 +52,7 @@ dev/build/node_modules/
node_modules/ node_modules/
vendor/ vendor/
php-vendor
tmp/ tmp/
#yarn #yarn

View File

@@ -97,7 +97,7 @@ class AdherentStats extends Stats
/** /**
* Return the number of proposition by month for a given year * Return the number of members by month for a given year
* *
* @param int $year Year * @param int $year Year
* @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month
@@ -375,7 +375,7 @@ class AdherentStats extends Stats
'datem' => $this->db->jdate($objp->datem), 'datem' => $this->db->jdate($objp->datem),
'status' => (int) $objp->status, 'status' => (int) $objp->status,
'date_end_subscription' => $this->db->jdate($objp->date_end_subscription), 'date_end_subscription' => $this->db->jdate($objp->date_end_subscription),
'photo' => $objp->photo, 'photo' => isset($objp->photo) ? (string) $objp->photo : null,
'email' => $objp->email, 'email' => $objp->email,
'gender' => $objp->gender, 'gender' => $objp->gender,
'morphy' => $objp->morphy, 'morphy' => $objp->morphy,

View File

@@ -26,6 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherentstats.class.php';
/** /**
@@ -44,6 +45,11 @@ class Members extends DolibarrApi
'typeid' 'typeid'
); );
/**
* @var AdherentStats
*/
public $memberstats;
/** /**
* Constructor * Constructor
*/ */
@@ -51,6 +57,7 @@ class Members extends DolibarrApi
{ {
global $db; global $db;
$this->db = $db; $this->db = $db;
$this->memberstats = new AdherentStats($this->db, DolibarrApiAccess::$user->socid, DolibarrApiAccess::$user->id);
} }
/** /**
@@ -982,6 +989,91 @@ class Members extends DolibarrApi
); );
} }
/**
* Return an array with the number of members by month for a given year
*
* @param int $year Year
* @param int $format 0=Label of abscissa is a translated text
* 1=Label of abscissa is month number
* 2=Label of abscissa is first letter of month
* @return array Array of statistics for last modified members
* @phan-return array<int<0,11>,array{0:int<1,12>,1:int}> Array of nb each month
* @phpstan-return array<int<0,11>,array{0:int<1,12>,1:int}> Array of nb each month
*
* @url GET stats/nbbymonth
* @throws RestException 403 Access denied
*/
public function getNbByMonth($year, $format = 0)
{
if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
throw new RestException(403);
}
return $this->memberstats->getNbByMonth($year, $format);
}
/**
* Return an array with the number of subscriptions by year
*
* @return array Array of statistics for last modified members
* @phan-return array<array{0:int,1:int}> Array of nb each year
* @phpstan-return array<array{0:int,1:int}> Array of nb each year
*
* @url GET stats/nbbyyear
* @throws RestException 403 Access denied
*/
public function getNbByYear()
{
if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
throw new RestException(403);
}
return $this->memberstats->getNbByYear();
}
/**
* Return the number of subscriptions by month for a given year
*
* @param int $year Year
* @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month
* @return array Array of statistics for last modified members
* @phan-return array<int<0,11>,array{0:int<1,12>,1:int|float}> Array of values by month
* @phpstan-return array<int<0,11>,array{0:int<1,12>,1:int|float}> Array of values by month
*
* @url GET stats/amountbymonth
* @throws RestException 403 Access denied
*/
public function getAmountByMonth($year, $format = 0)
{
if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
throw new RestException(403);
}
return $this->memberstats->getAmountByMonth($year, $format);
}
/**
* Last Modified Members
*
* Get an array of statistics for last modified members
*
* @param int $max Max numbers of members
* @return array Array of statistics for last modified members
* @phan-return array<int,array{id:int,ref:string,firstname:string,lastname:string,company:string,fk_soc:?int,datec:int|'',datem:int|'',status:int,date_end_subscription:int|'',photo:null|string,email:string,gender:string,morphy:string,typeid:int,need_subscription:0|1|null,subscription:'0'|'1'|null,label:string}>
* @phpstan-return array<int,array{id:int,ref:string,firstname:string,lastname:string,company:string,fk_soc:?int,datec:int|'',datem:int|'',status:int,date_end_subscription:int|'',photo:null|string,email:string,gender:string,morphy:string,typeid:int,need_subscription:0|1|null,subscription:'0'|'1'|null,label:string}>
*
* @url GET stats/lastmodifiedmembers
* @throws RestException 403 Access denied
*/
public function getLastModifiedMembers($max)
{
if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
throw new RestException(403);
}
return $this->memberstats->getLastModifiedMembers($max);
}
/** /**
* Validate fields before creating an object * Validate fields before creating an object
* *

View File

@@ -252,7 +252,7 @@ if (empty($error) && !empty($xml)) {
$out .= '<td></td>'."\n"; $out .= '<td></td>'."\n";
$out .= '<td>'.$langs->trans("ModuleMustBeEnabled", $langs->transnoentitiesnoconv("BlockedLog")).'</td>'."\n"; $out .= '<td>'.$langs->trans("ModuleMustBeEnabled", $langs->transnoentitiesnoconv("BlockedLog")).'</td>'."\n";
$out .= '<td class="center">'.yn(1).'</td>'."\n"; $out .= '<td class="center">'.yn(1).'</td>'."\n";
$out .= '<td class="center">'.yn(isModEnabled('blockedlog')).'</td>'."\n"; $out .= '<td class="center">'.yn(isModEnabled('blockedlog') ? 1 : 0).'</td>'."\n";
$out .= "</tr>\n"; $out .= "</tr>\n";
} }

View File

@@ -2653,7 +2653,7 @@ function getModuleDirForApiClass($moduleobject)
$moduledirforclass = 'contrat'; $moduledirforclass = 'contrat';
} elseif (in_array($moduleobject, array('admin', 'login', 'setup', 'access', 'status', 'tools', 'documents', 'objectlinks'))) { } elseif (in_array($moduleobject, array('admin', 'login', 'setup', 'access', 'status', 'tools', 'documents', 'objectlinks'))) {
$moduledirforclass = 'api'; $moduledirforclass = 'api';
} elseif ($moduleobject == 'contact' || $moduleobject == 'contacts' || $moduleobject == 'customer' || $moduleobject == 'thirdparty' || $moduleobject == 'thirdparties') { } elseif (in_array($moduleobject, ['contact', 'contacts', 'customer', 'thirdparty', 'thirdparties'])) {
$moduledirforclass = 'societe'; $moduledirforclass = 'societe';
} elseif ($moduleobject == 'propale' || $moduleobject == 'proposals') { } elseif ($moduleobject == 'propale' || $moduleobject == 'proposals') {
$moduledirforclass = 'comm/propal'; $moduledirforclass = 'comm/propal';
@@ -2661,7 +2661,7 @@ function getModuleDirForApiClass($moduleobject)
$moduledirforclass = 'comm/action'; $moduledirforclass = 'comm/action';
} elseif ($moduleobject == 'mailing') { } elseif ($moduleobject == 'mailing') {
$moduledirforclass = 'comm/mailing'; $moduledirforclass = 'comm/mailing';
} elseif ($moduleobject == 'adherent' || $moduleobject == 'members' || $moduleobject == 'memberstypes' || $moduleobject == 'subscriptions') { } elseif (in_array($moduleobject, ['adherent', 'members', 'memberstypes', 'subscriptions'])) {
$moduledirforclass = 'adherents'; $moduledirforclass = 'adherents';
} elseif ($moduleobject == 'don' || $moduleobject == 'donations') { } elseif ($moduleobject == 'don' || $moduleobject == 'donations') {
$moduledirforclass = 'don'; $moduledirforclass = 'don';

View File

@@ -156,7 +156,7 @@ class modMyModule extends DolibarrModules
$this->langfiles = array("mymodule@mymodule"); $this->langfiles = array("mymodule@mymodule");
// Prerequisites // Prerequisites
$this->phpmin = array(7, 1); // Minimum version of PHP required by module $this->phpmin = array(7, 2); // Minimum version of PHP required by module
// $this->phpmax = array(8, 0); // Maximum version of PHP required by module // $this->phpmax = array(8, 0); // Maximum version of PHP required by module
$this->need_dolibarr_version = array(19, -3); // Minimum version of Dolibarr required by module $this->need_dolibarr_version = array(19, -3); // Minimum version of Dolibarr required by module
// $this->max_dolibarr_version = array(19, -3); // Maximum version of Dolibarr required by module // $this->max_dolibarr_version = array(19, -3); // Maximum version of Dolibarr required by module

View File

@@ -2435,7 +2435,8 @@ class Product extends CommonObject
$price_min = $this->multiprices_min[$thirdparty_buyer->price_level]; $price_min = $this->multiprices_min[$thirdparty_buyer->price_level];
$price_min_ttc = $this->multiprices_min_ttc[$thirdparty_buyer->price_level]; $price_min_ttc = $this->multiprices_min_ttc[$thirdparty_buyer->price_level];
$price_base_type = $this->multiprices_base_type[$thirdparty_buyer->price_level]; $price_base_type = $this->multiprices_base_type[$thirdparty_buyer->price_level];
if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) {
// using this option is a bug. kept for backward compatibility
if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) { if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) {
$tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level]; $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level];
} }

View File

@@ -3,7 +3,7 @@
* Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat> * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net> * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com> * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr> * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by