\n";
$displayed_account_number = null; // Start with undefined to be able to distinguish with empty
+$objectstatic = null; // Init for static analysis
+$objectlink = ''; // Init for static analysis
+$result = -1; // Init for static analysis
+
// Loop on record
// --------------------------------------------------------------------
$i = 0;
@@ -1036,6 +1042,11 @@ $totalarray['val']['totaldebit'] = 0;
$totalarray['val']['totalcredit'] = 0;
$totalarray['val']['totalbalance'] = 0;
+// Init for static analysis
+$colspan = 0; // colspan before field 'label of operation'
+$colspanend = 0; // colspan after debit/credit
+$accountg = '-';
+
while ($i < min($num, $limit)) {
$line = $object->lines[$i];
diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php
index ddce2f4edc1..798c355ecd7 100644
--- a/htdocs/accountancy/class/accountancycategory.class.php
+++ b/htdocs/accountancy/class/accountancycategory.class.php
@@ -2,6 +2,7 @@
/* Copyright (C) 2016 Jamal Elbaz
* Copyright (C) 2016-2017 Alexandre Spangaro
* Copyright (C) 2018-2024 Frédéric France
+ * Copyright (C) 2024 MDW
*
* 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
@@ -113,12 +114,12 @@ class AccountancyCategory // extends CommonObject
public $active;
/**
- * @var array Lines cptbk
+ * @var Object[] Lines cptbk
*/
public $lines_cptbk;
/**
- * @var array Lines display
+ * @var Object[] Lines display
*/
public $lines_display;
@@ -133,7 +134,7 @@ class AccountancyCategory // extends CommonObject
public $sdcpermonth;
/**
- * @var array Sum debit credit per account
+ * @var array Sum debit credit per account
*/
public $sdcperaccount;
@@ -508,8 +509,8 @@ class AccountancyCategory // extends CommonObject
/**
* Function to add an accounting account in an accounting category
*
- * @param int $id_cat Id category
- * @param array $cpts list of accounts array
+ * @param int $id_cat Id category
+ * @param array $cpts list of accounts array
*
* @return int Return integer <0 if KO, >0 if OK
*/
@@ -619,11 +620,11 @@ class AccountancyCategory // extends CommonObject
/**
* Function to show result of an accounting account from the ledger with a direction and a period
*
- * @param int|array $cpt Accounting account or array of accounting account
+ * @param int|array $cpt Accounting account or array of accounting account
* @param string $date_start Date start
* @param string $date_end Date end
- * @param int $sens Sens of the account: 0: credit - debit (use this by default), 1: debit - credit
- * @param string $thirdparty_code Thirdparty code
+ * @param int<0,1> $sens Sens of the account: 0: credit - debit (use this by default), 1: debit - credit
+ * @param string $thirdparty_code Third party code
* @param int $month Specific month - Can be empty
* @param int $year Specific year - Can be empty
* @return integer Return integer <0 if KO, >= 0 if OK
@@ -635,8 +636,9 @@ class AccountancyCategory // extends CommonObject
$this->sdc = 0;
$this->sdcpermonth = array();
+ $listofaccount = '';
+
if (is_array($cpt)) {
- $listofaccount = '';
foreach ($cpt as $cptcursor) {
if (! is_null($cptcursor)) {
if ($listofaccount) {
@@ -710,7 +712,7 @@ class AccountancyCategory // extends CommonObject
* Function to get an array of all active custom groups (llx_c_accunting_categories) with their accounts from the chart of account (ll_accounting_acount)
*
* @param int $catid Custom group ID
- * @return array|integer Result in table (array), -1 if KO
+ * @return array>|int<-1,-1> Result in table (array), -1 if KO
* @see getCats(), getCptsCat()
*/
public function getCatsCpts($catid = 0)
@@ -837,7 +839,7 @@ class AccountancyCategory // extends CommonObject
* @param string $predefinedgroupwhere Sql criteria filter to select accounting accounts. This value must be sanitized and not come from an input of a user.
* Example: "pcg_type = 'EXPENSE' AND fk_pcg_version = 'xx'"
* Example: "fk_accounting_category = 99"
- * @return array|int Array of accounting accounts or -1 if error
+ * @return array|int<-1,-1> Array of accounting accounts or -1 if error
* @see getCats(), getCatsCpts()
*/
public function getCptsCat($cat_id, $predefinedgroupwhere = '')
diff --git a/htdocs/accountancy/class/accountancyimport.class.php b/htdocs/accountancy/class/accountancyimport.class.php
index 7cba6c8bfb7..d971ddd8d7f 100644
--- a/htdocs/accountancy/class/accountancyimport.class.php
+++ b/htdocs/accountancy/class/accountancyimport.class.php
@@ -63,8 +63,8 @@ class AccountancyImport
/**
* Clean amount
*
- * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
- * @param array $listfields Fields list to add
+ * @param array}> $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
+ * @param array $listfields Fields list to add
* @param int $record_key Record key
* @return float Value
*/
@@ -77,8 +77,8 @@ class AccountancyImport
/**
* Clean value with trim
*
- * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
- * @param array $listfields Fields list to add
+ * @param array}> $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
+ * @param array $listfields Fields list to add
* @param int $record_key Record key
* @return mixed Value
*/
@@ -90,8 +90,8 @@ class AccountancyImport
/**
* Compute amount
*
- * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
- * @param array $listfields Fields list to add
+ * @param array}> $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
+ * @param array $listfields Fields list to add
* @param int $record_key Record key
* @return string Value
*/
@@ -119,8 +119,8 @@ class AccountancyImport
/**
* Compute direction
*
- * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
- * @param array $listfields Fields list to add
+ * @param array}> $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
+ * @param array $listfields Fields list to add
* @param int $record_key Record key
* @return string Value
*/
@@ -145,8 +145,8 @@ class AccountancyImport
/**
* Compute piece number
*
- * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
- * @param array $listfields Fields list to add
+ * @param array}> $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
+ * @param array $listfields Fields list to add
* @param int $record_key Record key
* @return string Value
*/
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index 329b2986fe6..60022ab0cff 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -145,7 +145,7 @@ class AccountingAccount extends CommonObject
public $reconcilable;
/**
- * @var array cache array
+ * @var array cache array
*/
private $accountingaccount_codetotid_cache = array();
@@ -729,9 +729,9 @@ class AccountingAccount extends CommonObject
* @param Product $product Product object sell or buy
* @param Facture|FactureFournisseur $facture Facture
* @param FactureLigne|SupplierInvoiceLine $factureDet Facture Det
- * @param array $accountingAccount Array of Accounting account
+ * @param array $accountingAccount Array of Accounting account
* @param string $type Customer / Supplier
- * @return array|int Array of accounting accounts suggested or < 0 if technical error.
+ * @return array{suggestedaccountingaccountbydefaultfor:string,suggestedaccountingaccountfor:string,suggestedid:?int,code_l:string,code_p:string,code_t:string}|int<-1,-1> Array of accounting accounts suggested or < 0 if technical error.
* 'suggestedaccountingaccountbydefaultfor'=>Will be used for the label to show on tooltip for account by default on any product
* 'suggestedaccountingaccountfor'=>Is the account suggested for this product
*/
@@ -745,6 +745,7 @@ class AccountingAccount extends CommonObject
$parameters = array('buyer' => $buyer, 'seller' => $seller, 'product' => $product, 'facture' => $facture, 'factureDet' => $factureDet ,'accountingAccount' => $accountingAccount, 0 => $type);
$reshook = $hookmanager->executeHooks('accountancyBindingCalculation', $parameters); // Note that $action and $object may have been modified by some hooks
+ $result = -1; // Init for static analysis
if (empty($reshook)) {
$const_name = '';
if ($type == 'customer') {
diff --git a/htdocs/accountancy/class/api_accountancy.class.php b/htdocs/accountancy/class/api_accountancy.class.php
index bbb30cbbf3c..61faec2bc51 100644
--- a/htdocs/accountancy/class/api_accountancy.class.php
+++ b/htdocs/accountancy/class/api_accountancy.class.php
@@ -2,6 +2,7 @@
/* Copyright (C) 2015 Jean-François Ferry
* Copyright (C) 2019 Cedric Ancelin
* Copyright (C) 2023 Lionel Vessiller
+ * Copyright (C) 2024 MDW
*
* 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
@@ -30,7 +31,7 @@ class Accountancy extends DolibarrApi
{
/**
*
- * @var array $FIELDS Mandatory fields, checked when create and update object
+ * @var string[] $FIELDS Mandatory fields, checked when create and update object
*/
public static $FIELDS = array();
@@ -40,7 +41,7 @@ class Accountancy extends DolibarrApi
public $bookkeeping;
/**
- * @var AccountancyExport $accountancy_export {@type AccountancyExport}
+ * @var AccountancyExport $accountancyexport {@type AccountancyExport}
*/
public $accountancyexport;
@@ -137,7 +138,7 @@ class Accountancy extends DolibarrApi
// set filter for each period available
$filter = array();
$doc_date_start = null;
- $doc_date_end= null;
+ $doc_date_end = null;
$now = dol_now();
$now_arr = dol_getdate($now);
$now_month = $now_arr['mon'];
@@ -173,9 +174,9 @@ class Accountancy extends DolibarrApi
$prev_month_date_list = array();
$prev_month_date_list[] = dol_get_prev_month($now_month, $now_year); // get previous month for index = 0
for ($i = 1; $i < $nb_prev_month; $i++) {
- $prev_month_date_list[] = dol_get_prev_month($prev_month_date_list[$i-1]['month'], $prev_month_date_list[$i-1]['year']); // get i+1 previous month for index=i
+ $prev_month_date_list[] = dol_get_prev_month($prev_month_date_list[$i - 1]['month'], $prev_month_date_list[$i - 1]['year']); // get i+1 previous month for index=i
}
- $doc_date_start = dol_mktime(0, 0, 0, $prev_month_date_list[$nb_prev_month-1]['month'], 1, $prev_month_date_list[$nb_prev_month-1]['year']); // first day of n previous month for index=n-1
+ $doc_date_start = dol_mktime(0, 0, 0, $prev_month_date_list[$nb_prev_month - 1]['month'], 1, $prev_month_date_list[$nb_prev_month - 1]['year']); // first day of n previous month for index=n-1
$doc_date_end = dol_get_last_day($prev_month_date_list[0]['year'], $prev_month_date_list[0]['month']); // last day of previous month for index = 0
} elseif ($period == 'currentyear' || $period == 'lastyear') {
$period_year = $now_year;
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 76f7b43a620..89ed928d99b 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -408,7 +408,7 @@ class BookKeeping extends CommonObject
$sql .= ', entity';
$sql .= ") VALUES (";
$sql .= "'".$this->db->idate($this->doc_date)."'";
- $sql .= ", ".(isDolTms($this->date_lim_reglement) ? "'".$this->db->idate($this->date_lim_reglement)."'" : 'NULL');
+ $sql .= ", ".(isDolTms($this->date_lim_reglement) ? "'".$this->db->idate($this->date_lim_reglement)."'" : 'NULL');
$sql .= ", '".$this->db->escape($this->doc_type)."'";
$sql .= ", '".$this->db->escape($this->doc_ref)."'";
$sql .= ", ".((int) $this->fk_doc);
@@ -839,7 +839,7 @@ class BookKeeping extends CommonObject
* @param string $sortfield Sort field
* @param int $limit limit
* @param int $offset offset limit
- * @param array $filter filter array
+ * @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
* @param int $option option (0: general account or 1: subaccount)
* @param int $countonly Do not fill the $object->lines, return only the count.
@@ -1040,7 +1040,7 @@ class BookKeeping extends CommonObject
* @param string $sortfield Sort field
* @param int $limit Limit
* @param int $offset Offset limit
- * @param string|array $filter Filter array
+ * @param string|array $filter Filter array
* @param string $filtermode Filter mode (AND or OR)
* @param int $showAlreadyExportMovements Show movements when field 'date_export' is not empty (0:No / 1:Yes (Default))
* @return int Return integer <0 if KO, >0 if OK
@@ -1228,7 +1228,7 @@ class BookKeeping extends CommonObject
* @param string $sortfield Sort field
* @param int $limit Limit
* @param int $offset Offset limit
- * @param string|array $filter Filter
+ * @param string|array $filter Filter
* @param string $filtermode Filter mode (AND or OR)
* @param int $option option (0: aggregate by general account or 1: aggreegate by subaccount)
* @return int Return integer <0 if KO, >0 if OK
@@ -2180,11 +2180,11 @@ class BookKeeping extends CommonObject
*
* @param string $selectid Preselected chart of accounts
* @param string $htmlname Name of field in html form
- * @param int $showempty Add an empty field
- * @param array $event Event options
+ * @param int<0,1> $showempty Add an empty field
+ * @param array}> $event Event options
* @param int $select_in Value is a aa.rowid (0 default) or aa.account_number (1)
* @param int $select_out Set value returned by select 0=rowid (default), 1=account_number
- * @param string $aabase Set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number
+ * @param string $aabase Set accounting_account base class to display empty=all or from 1 to 8 will display only account starting from this number
* @return string|int String with HTML select or -1 if KO
*/
public function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '')
@@ -2251,7 +2251,7 @@ class BookKeeping extends CommonObject
* FIXME: This function takes the parent of parent to get the root account !
*
* @param string $account Accounting account
- * @return array|int Array with root account information (max 2 upper level), <0 if KO
+ * @return array{id:int,account_number:string,label:string}|int<-1,-1> Array with root account information (max 2 upper level), <0 if KO
*/
public function getRootAccount($account = null)
{
@@ -2565,7 +2565,7 @@ class BookKeeping extends CommonObject
*
* @param int $date_start Date start
* @param int $date_end Date end
- * @return array|int Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
+ * @return array{total:int,list:array,int>,total:int}>}|int<-1,-1> Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
*/
public function getCountByMonthForFiscalPeriod($date_start, $date_end)
{
@@ -2790,9 +2790,11 @@ class BookKeeping extends CommonObject
$this->errors[] = $langs->trans('ErrorRecordNotFound') . ' - ' . $langs->trans('Codejournal') . ' (' . $langs->trans('AccountingJournalType9') . ')';
$error++;
}
+ } else {
+ $journal = null;
}
- if (!$error) {
+ if (!$error && is_object($journal)) {
$accounting_groups_used_for_balance_sheet_account = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))), 'strlen');
$accounting_groups_used_for_income_statement = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))), 'strlen');
@@ -2886,7 +2888,7 @@ class BookKeeping extends CommonObject
if (!$error && $income_statement_amount != 0) {
$mt = $income_statement_amount;
$accountingaccount = new AccountingAccount($this->db);
- $accountingaccount->fetch(null, getDolGlobalString($income_statement_amount < 0 ? 'ACCOUNTING_RESULT_LOSS' : 'ACCOUNTING_RESULT_PROFIT'), true);
+ $accountingaccount->fetch(0, getDolGlobalString($income_statement_amount < 0 ? 'ACCOUNTING_RESULT_LOSS' : 'ACCOUNTING_RESULT_PROFIT'), true);
$bookkeeping = new BookKeeping($this->db);
$bookkeeping->doc_date = $new_fiscal_period->date_start;
diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php
index 5f47641fa5c..c2ad7f05320 100644
--- a/htdocs/accountancy/class/lettering.class.php
+++ b/htdocs/accountancy/class/lettering.class.php
@@ -3,6 +3,7 @@
* Copyright (C) 2013 Olivier Geffroy
* Copyright (C) 2013-2024 Alexandre Spangaro
* Copyright (C) 2018 Frédéric France
+ * Copyright (C) 2024 MDW
*
* 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
@@ -33,6 +34,9 @@ include_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
*/
class Lettering extends BookKeeping
{
+ /**
+ * @var array}>
+ */
public static $doc_type_infos = array(
'customer_invoice' => array(
'payment_table' => 'paiement',
@@ -289,7 +293,7 @@ class Lettering extends BookKeeping
/**
*
- * @param array $ids ids array
+ * @param int[] $ids ids array
* @param int $notrigger no trigger
* @param bool $partial Partial lettering
* @return int
@@ -316,11 +320,15 @@ class Lettering extends BookKeeping
$resql = $this->db->query($sql);
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
- if (empty($obj->lettering_code)) continue;
+ if (empty($obj->lettering_code)) {
+ continue;
+ }
// Remove normal lettering code if set partial lettering
if ($partial && preg_match('/^[A-Z]+$/', $obj->lettering_code)) {
- if (!empty($obj->bookkeeping_ids)) $ids = array_diff($ids, explode(',', $obj->bookkeeping_ids));
+ if (!empty($obj->bookkeeping_ids)) {
+ $ids = array_diff($ids, explode(',', $obj->bookkeeping_ids));
+ }
} elseif (!$partial && preg_match('/^[a-z]+$/', $obj->lettering_code)) {
// Delete partial lettering code if set normal lettering
$sql2 = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET";
@@ -427,7 +435,7 @@ class Lettering extends BookKeeping
/**
*
- * @param array $ids ids array
+ * @param int[] $ids ids array
* @param int $notrigger no trigger
* @return int Nb of affectd rows or <0 if error
*/
@@ -463,7 +471,7 @@ class Lettering extends BookKeeping
/**
* Lettering bookkeeping lines all types
*
- * @param array $bookkeeping_ids Lettering specific list of bookkeeping id
+ * @param int[] $bookkeeping_ids Lettering specific list of bookkeeping id
* @param bool $unlettering Do unlettering
* @return int Return integer <0 if error (nb lettered = result -1), 0 if noting to lettering, >0 if OK (nb lettered)
*/
@@ -495,7 +503,7 @@ class Lettering extends BookKeeping
/**
* Lettering bookkeeping lines
*
- * @param array $bookkeeping_ids Lettering specific list of bookkeeping id
+ * @param int[] $bookkeeping_ids Lettering specific list of bookkeeping id
* @param bool $unlettering Do unlettering
* @return int Return integer <0 if error (nb lettered = result -1), 0 if noting to lettering, >0 if OK (nb lettered)
*/
@@ -581,9 +589,9 @@ class Lettering extends BookKeeping
/**
* Lettering bookkeeping lines
*
- * @param array $bookkeeping_ids Lettering specific list of bookkeeping id
+ * @param int[] $bookkeeping_ids Lettering specific list of bookkeeping id
* @param bool $only_has_subledger_account Get only lines who have subledger account
- * @return array|int Return integer <0 if error otherwise all linked lines by block
+ * @return int<-1,-1>|array> Return integer <0 if error otherwise all linked lines by block
*/
public function getLinkedLines($bookkeeping_ids, $only_has_subledger_account = true)
{
@@ -719,8 +727,8 @@ class Lettering extends BookKeeping
/**
* Get all fk_doc by doc_type from list of bank ids
*
- * @param array $bank_ids List of bank ids
- * @return array|int Return integer <0 if error otherwise all fk_doc by doc_type
+ * @param int[] $bank_ids List of bank ids
+ * @return array>|int Return integer <0 if error otherwise all fk_doc by doc_type
*/
public function getDocTypeAndFkDocFromBankLines($bank_ids)
{
@@ -761,9 +769,9 @@ class Lettering extends BookKeeping
/**
* Get all bank ids from list of document ids of a type
*
- * @param array $document_ids List of document id
+ * @param array $document_ids List of document id
* @param string $doc_type Type of document ('customer_invoice' or 'supplier_invoice', ...)
- * @return array|int Return integer <0 if error otherwise all all bank ids from list of document ids of a type
+ * @return array|int<-1,-1> Return integer <0 if error otherwise all all bank ids from list of document ids of a type
*/
public function getBankLinesFromFkDocAndDocType($document_ids, $doc_type)
{
@@ -794,6 +802,7 @@ class Lettering extends BookKeeping
$sql = "SELECT DISTINCT p." . $this->db->sanitize($doc_type_info['payment_table_fk_bank']) . " AS fk_doc";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->db->sanitize($doc_type_info['payment_table']) . " AS p";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $this->db->sanitize($doc_type_info['doc_payment_table']) . " AS dp ON dp." . $this->db->sanitize($doc_type_info['doc_payment_table_fk_payment']) . " = p.rowid";
+ // Implode used on array of int @phan-suppress-next-line PhanTypeMismatchArgumentInternal
$sql .= " WHERE dp." . $this->db->sanitize($doc_type_info['doc_payment_table_fk_doc']) . " IN (" . $this->db->sanitize(implode(',', $document_ids)) . ")";
$sql .= " AND p." . $this->db->sanitize($doc_type_info['payment_table_fk_bank']) . " > 0";
@@ -815,9 +824,9 @@ class Lettering extends BookKeeping
/**
* Get all linked document ids by group and type
*
- * @param array $document_ids List of document id
+ * @param int[] $document_ids List of document id
* @param string $doc_type Type of document ('customer_invoice' or 'supplier_invoice', ...)
- * @return array|int Return integer <0 if error otherwise all linked document ids by group and type [ [ 'doc_type' => [ doc_id, ... ], ... ], ... ]
+ * @return array>|int<-1,-1> Return integer <0 if error otherwise all linked document ids by group and type [ [ 'doc_type' => [ doc_id, ... ], ... ], ... ]
*/
public function getLinkedDocumentByGroup($document_ids, $doc_type)
{
@@ -903,11 +912,11 @@ class Lettering extends BookKeeping
/**
* Get element ids grouped by link or element in common
*
- * @param array $link_by_element List of payment ids by link key
- * @param array $element_by_link List of element ids by link key
- * @param string $link_key Link key (used for recursive function)
- * @param array $current_group Current group (used for recursive function)
- * @return array List of element ids grouped by link or element in common
+ * @param array> $link_by_element List of payment ids by link key
+ * @param array> $element_by_link List of element ids by link key
+ * @param string $link_key Link key (used for recursive function)
+ * @param array $current_group Current group (used for recursive function)
+ * @return array> List of element ids grouped by link or element in common
*/
public function getGroupElements(&$link_by_element, &$element_by_link, $link_key = '', &$current_group = array())
{
@@ -917,8 +926,9 @@ class Lettering extends BookKeeping
return $grouped_elements;
}
+
if (empty($link_key)) {
- // Save list when is the begin of recursive function
+ // Save list when is the first step of the recursive recursive function
$save_link_by_element = $link_by_element;
$save_element_by_link = $element_by_link;
}
@@ -957,8 +967,8 @@ class Lettering extends BookKeeping
if (empty($link_key)) {
// Restore list when is the begin of recursive function
- $link_by_element = $save_link_by_element;
- $element_by_link = $save_element_by_link;
+ $link_by_element = $save_link_by_element; // @phan-suppress-current-line PhanPossiblyUndeclaredVariable
+ $element_by_link = $save_element_by_link; // @phan-suppress-current-line PhanPossiblyUndeclaredVariable
}
return $grouped_elements;
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 578ad537b7d..7185ef0b283 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -7,6 +7,7 @@
* Copyright (C) 2016 Laurent Destailleur
* Copyright (C) 2021 Gauthier VERDOL
* Copyright (C) 2024 Frédéric France
+ * Copyright (C) 2024 MDW
*
* 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
@@ -550,6 +551,8 @@ if ($result) {
$accountingaccount_codetotid_cache = array();
+ $suggestedaccountingaccountfor = ''; // Initialise (for static analysis)
+ $suggestedaccountingaccountbydefaultfor = '';
while ($i < min($num_lines, $limit)) {
$objp = $db->fetch_object($result);
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index cddde9a1fb3..c07fab944a8 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -113,6 +113,9 @@ $error = 0;
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
+$pastmonth = null; // Initialise for static analysis (could be really unseg)
+$pastmonthyear = null;
+
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
@@ -199,6 +202,7 @@ $tmppayment = new Paiement($db);
$tmpinvoice = new Facture($db);
$accountingaccount = new AccountingAccount($db);
+$account_transfer = 'NotDefined'; // For static analysis, NotDefined is a reserved word
// Get code of finance journal
$accountingjournalstatic = new AccountingJournal($db);
@@ -631,19 +635,19 @@ if (!$error && $action == 'writebookkeeping' && $user->hasRight('accounting', 'b
$now = dol_now();
$accountingaccountcustomer = new AccountingAccount($db);
- $accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
+ $accountingaccountcustomer->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
$accountingaccountsupplier = new AccountingAccount($db);
- $accountingaccountsupplier->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
+ $accountingaccountsupplier->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
$accountingaccountpayment = new AccountingAccount($db);
- $accountingaccountpayment->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true);
+ $accountingaccountpayment->fetch(0, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true);
$accountingaccountexpensereport = new AccountingAccount($db);
- $accountingaccountexpensereport->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT, true);
+ $accountingaccountexpensereport->fetch(0, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT, true);
$accountingaccountsuspense = new AccountingAccount($db);
- $accountingaccountsuspense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true);
+ $accountingaccountsuspense->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true);
$error = 0;
foreach ($tabpay as $key => $val) { // $key is rowid into llx_bank
@@ -791,43 +795,43 @@ if (!$error && $action == 'writebookkeeping' && $user->hasRight('accounting', 'b
} elseif (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'payment_vat') {
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'payment_donation') {
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'member') {
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'payment_loan') {
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'payment_various') {
$bookkeeping->subledger_account = $k;
$bookkeeping->subledger_label = $tabcompany[$key]['name'];
- $accountingaccount->fetch(null, $tabpay[$key]["account_various"], true); // TODO Use a cache
+ $accountingaccount->fetch(0, $tabpay[$key]["account_various"], true); // TODO Use a cache
$bookkeeping->numero_compte = $tabpay[$key]["account_various"];
$bookkeeping->label_compte = $accountingaccount->label;
} elseif ($tabtype[$key] == 'banktransfert') {
$bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = '';
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $accountingaccount->label;
} else {
@@ -1097,7 +1101,7 @@ if (empty($action) || $action == 'view') {
$variousstatic = new PaymentVarious($db);
$title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
- $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
+ $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-bankjournal');
$nom = $title;
@@ -1475,7 +1479,7 @@ $db->close();
/**
* Return source for doc_ref of a bank transaction
*
- * @param array $val Array of val
+ * @param array $val Array of val
* @param string $typerecord Type of record ('payment', 'payment_supplier', 'payment_expensereport', 'payment_vat', ...)
* @return string A string label to describe a record into llx_bank_url
*/
diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php
index 324b5e168a6..681ffd5d0ac 100644
--- a/htdocs/accountancy/journal/expensereportsjournal.php
+++ b/htdocs/accountancy/journal/expensereportsjournal.php
@@ -8,6 +8,7 @@
* Copyright (C) 2013-2016 Florian Henry
* Copyright (C) 2018 Frédéric France
* Copyright (C) 2018 Eric Seigne
+ * Copyright (C) 2024 MDW
*
* 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
@@ -60,6 +61,13 @@ $now = dol_now();
$hookmanager->initHooks(array('expensereportsjournal'));
$parameters = array();
+$taber = array(); // Initialise for static analysis
+$tabht = array();
+$tabtva = array();
+$tabttc = array();
+$tablocaltax1 = array();
+$tablocaltax2 = array();
+
// Security check
if (!isModEnabled('accounting')) {
accessforbidden();
@@ -90,6 +98,9 @@ $journal_label = $accountingjournalstatic->label;
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
+$pastmonth = null; // Initialise (could be unset)
+$pastmonthyear = null; // Initialise (could be unset)
+
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
@@ -251,7 +262,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
$error = 0;
$accountingaccountexpense = new AccountingAccount($db);
- $accountingaccountexpense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'), true);
+ $accountingaccountexpense->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT'), true);
foreach ($taber as $key => $val) { // Loop on each expense report
$errorforline = 0;
@@ -322,7 +333,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
foreach ($tabht[$key] as $k => $mt) {
if ($mt) {
// get compte id and label
- if ($accountingaccount->fetch(null, $k, true)) {
+ if ($accountingaccount->fetch(0, $k, true)) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
@@ -523,7 +534,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
// Fees
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
- $accountingaccount->fetch(null, $k, true);
+ $accountingaccount->fetch(0, $k, true);
if ($mt) {
print '"'.$date.'"'.$sep;
print '"'.$val["ref"].'"'.$sep;
@@ -563,7 +574,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
if (empty($action) || $action == 'view') {
$title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
- $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
+ $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-expensereportsjournal');
$nom = $title;
@@ -573,7 +584,7 @@ if (empty($action) || $action == 'view') {
$builddate = dol_now();
$description = $langs->trans("DescJournalOnlyBindedVisible").' ';
- $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger"));
+ $listofchoices = array('notyet' => $langs->trans("NotYetInGeneralLedger"), 'already' => $langs->trans("AlreadyInGeneralLedger"));
$period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0);
$period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index f5f41f05fab..31e08f0bdaf 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -75,6 +75,17 @@ if (!$user->hasRight('accounting', 'bind', 'write')) {
$error = 0;
+$tabfac = array();
+$tabht = array();
+$tabtva = array();
+$tabttc = array();
+$tablocaltax1 = array();
+$tablocaltax2 = array();
+$tabrctva = array();
+$tabrclocaltax1 = array();
+$tabrclocaltax2 = array();
+$tabpay = array();
+
/*
* Actions
@@ -93,6 +104,9 @@ $journal_label = $accountingjournalstatic->label;
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
+$pastmonth = null; // Initialise, could be unset
+$pastmonthyear = null; // Initialise, could be unset
+
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
@@ -400,7 +414,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
$invoicestatic = new FactureFournisseur($db);
$accountingaccountsupplier = new AccountingAccount($db);
- $accountingaccountsupplier->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
+ $accountingaccountsupplier->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0;
@@ -614,7 +628,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
foreach ($arrayofvat[$key] as $k => $mt) {
if ($mt) {
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache for label
$label_account = $accountingaccount->label;
$bookkeeping = new BookKeeping($db);
@@ -833,7 +847,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
// Product / Service
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
- $accountingaccount->fetch(null, $k, true);
+ $accountingaccount->fetch(0, $k, true);
//if ($mt) {
print '"'.$key.'"'.$sep;
print '"'.$date.'"'.$sep;
@@ -929,7 +943,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
if (empty($action) || $action == 'view') {
$title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
- $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
+ $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-purchasesjournal');
$nom = $title;
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 9bc5672aeba..086cb033bca 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -77,6 +77,14 @@ if (!$user->hasRight('accounting', 'bind', 'write')) {
$error = 0;
+$tabfac = array();
+$tabht = array();
+$tabtva = array();
+$tabwarranty = array();
+$tabttc = array();
+$tablocaltax1 = array();
+$tablocaltax2 = array();
+
/*
* Actions
@@ -95,6 +103,9 @@ $journal_label = $accountingjournalstatic->label;
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
+$pastmonth = null; // Initialise, could be unset
+$pastmonthyear = null; // Initialise, could be unset
+
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
@@ -427,10 +438,10 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
$invoicestatic = new Facture($db);
$accountingaccountcustomer = new AccountingAccount($db);
- $accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
+ $accountingaccountcustomer->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
$accountingaccountcustomerwarranty = new AccountingAccount($db);
- $accountingaccountcustomerwarranty->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true);
+ $accountingaccountcustomerwarranty->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true);
foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0;
@@ -670,7 +681,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
foreach ($arrayofvat[$key] as $k => $mt) {
if ($mt) {
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache for label
$label_account = $accountingaccount->label;
$bookkeeping = new BookKeeping($db);
@@ -731,7 +742,7 @@ if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'b
if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) {
foreach ($tabrevenuestamp[$key] as $k => $mt) {
if ($mt) {
- $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label
+ $accountingaccount->fetch(0, $k, true); // TODO Use a cache for label
$label_account = $accountingaccount->label;
$bookkeeping = new BookKeeping($db);
@@ -922,7 +933,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
// Product / Service
foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db);
- $accountingaccount->fetch(null, $k, true);
+ $accountingaccount->fetch(0, $k, true);
//if ($mt) {
print '"'.$key.'"'.$sep;
print '"'.$date.'"'.$sep;
@@ -997,7 +1008,7 @@ if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 !
if (empty($action) || $action == 'view') {
$title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
- $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
+ $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-sellsjournal');
$nom = $title;
diff --git a/htdocs/accountancy/journal/variousjournal.php b/htdocs/accountancy/journal/variousjournal.php
index 5ba196ae95d..60050fa52b4 100644
--- a/htdocs/accountancy/journal/variousjournal.php
+++ b/htdocs/accountancy/journal/variousjournal.php
@@ -1,5 +1,6 @@
+ * Copyright (C) 2024 MDW
*
* 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
@@ -61,6 +62,9 @@ $parameters = array();
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
+$pastmonth = null; // Initialise, could be unset
+$pastmonthyear = null; // Initialise, could be unset
+
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
@@ -196,7 +200,7 @@ if ($object->nature == 2) {
}
$title = $langs->trans("GenerationOfAccountingEntries") . ' - ' . $object->getNomUrl(0, 2, 1, '', 1);
-$help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
+$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Génération_des_écritures_en_comptabilité';
llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-variousjournal');
$nom = $title;
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index b640b0a1bb8..0691dce7a09 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -7,6 +7,7 @@
* Copyright (C) 2014 Juanjo Menent s
* Copyright (C) 2016 Laurent Destailleur
* Copyright (C) 2024 Frédéric France
+ * Copyright (C) 2024 MDW
*
* 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
@@ -561,6 +562,8 @@ if ($result) {
$accountingaccount_codetotid_cache = array();
+ $suggestedaccountingaccountfor = '';
+ $suggestedaccountingaccountbydefaultfor = '';
while ($i < min($num_lines, $limit)) {
$objp = $db->fetch_object($result);
diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php
index 427751e574e..60630b9c860 100644
--- a/htdocs/core/class/html.formaccounting.class.php
+++ b/htdocs/core/class/html.formaccounting.class.php
@@ -73,15 +73,15 @@ class FormAccounting extends Form
/**
* Return list of journals with label by nature
*
- * @param string $selectid Preselected journal code
- * @param string $htmlname Name of field in html form
- * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
- * @param int $showempty Add an empty field
- * @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code
- * @param int $select_out Set value returned by select. 0=rowid (default), 1=code
- * @param string $morecss More css non HTML object
- * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache.
- * @param int $disabledajaxcombo Disable ajax combo box.
+ * @param string $selectid Preselected journal code
+ * @param string $htmlname Name of field in html form
+ * @param int<0,9> $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
+ * @param int<0,1> $showempty Add an empty field
+ * @param int<0,1> $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code
+ * @param int<0,1> $select_out Set value returned by select. 0=rowid (default), 1=code
+ * @param string $morecss More css non HTML object
+ * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache.
+ * @param int<0,1> $disabledajaxcombo Disable ajax combo box.
* @return string|int String with HTML select, or -1 if error
*/
public function select_journal($selectid, $htmlname = 'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss = 'maxwidth300 maxwidthonsmartphone', $usecache = '', $disabledajaxcombo = 0)
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 5a40f704af9..ff81ca552c4 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -445,7 +445,7 @@ function ajax_dialog($title, $message, $w = 350, $h = 150)
* TODO: It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html.formcompany.class.php. Should use ajax_autocompleter instead like done by html.form.class.php for select_produits.
*
* @param string $htmlname Name of html select field ('myid' or '.myclass')
- * @param array $events More events option. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @param array}> $events More events option. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @param int $forcefocus Force focus on field
* @param string $widthTypeOfAutocomplete 'resolve' or 'off'
diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php
index 8cd7699aa3f..076c37893d7 100644
--- a/htdocs/projet/class/api_projects.class.php
+++ b/htdocs/projet/class/api_projects.class.php
@@ -194,9 +194,10 @@ class Projects extends DolibarrApi
* @param int $category Use this param to filter list by category
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
+ * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0*
* @return array Array of project objects
*/
- public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $properties = '')
+ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
{
if (!DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
throw new RestException(403);
@@ -244,6 +245,9 @@ class Projects extends DolibarrApi
}
}
+ //this query will return total orders with the filters given
+ $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
+
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
@@ -273,6 +277,23 @@ class Projects extends DolibarrApi
throw new RestException(503, 'Error when retrieve project list : '.$this->db->lasterror());
}
+ //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
+ if ($pagination_data) {
+ $totalsResult = $this->db->query($sqlTotals);
+ $total = $this->db->fetch_object($totalsResult)->total;
+
+ $tmp = $obj_ret;
+ $obj_ret = [];
+
+ $obj_ret['data'] = $tmp;
+ $obj_ret['pagination'] = [
+ 'total' => (int) $total,
+ 'page' => $page, //count starts from 0
+ 'page_count' => ceil((int) $total / $limit),
+ 'limit' => $limit
+ ];
+ }
+
return $obj_ret;
}