Fix phpcs

This commit is contained in:
Laurent Destailleur 2021-03-04 19:20:16 +01:00
parent 525d643915
commit c044b43b66
6 changed files with 614 additions and 676 deletions

View File

@ -1,4 +1,6 @@
#!/bin/sh
# To install this precommit file: TODO
# To run the fix manually: cd ~/git/dolibarr; phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true fileordir
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`

View File

@ -451,7 +451,7 @@ if ($action == 'create') {
print '<input name="amount" id="amount" class="minwidth100" value="'.GETPOST("amount").'">';
print '</td></tr>';
// Project
// Project
if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
@ -643,7 +643,6 @@ if ($id) {
print '<tr><td>'.$langs->trans("DateStartPeriod")."</td><td>";
print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
print "</td></tr>";
} else {
print "<tr>";
print '<td>' . $langs->trans("DateStartPeriod") . '</td><td>';
@ -651,7 +650,6 @@ if ($id) {
print '</td></tr>';
}
if ($action == 'edit') {
print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
@ -801,8 +799,7 @@ if ($id) {
$totalpaye += $objp->amount;
$i++;
}
}
else {
} else {
print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
print '<td></td><td></td><td></td><td></td>';
print '</tr>';
@ -821,8 +818,7 @@ if ($id) {
print '</div>';
$db->free($resql);
}
else {
} else {
dol_print_error($db);
}

View File

@ -49,8 +49,8 @@ class PaymentSalary extends CommonObject
public $picto = 'payment';
/**
* @var int ID
*/
* @var int ID
*/
public $fk_salary;
public $datec = '';
@ -63,12 +63,12 @@ class PaymentSalary extends CommonObject
*/
public $total;
public $amount; // Total amount of payment
public $amounts = array(); // Array of amounts
public $amount; // Total amount of payment
public $amounts = array(); // Array of amounts
/**
* @var int ID
*/
/**
* @var int ID
*/
public $fk_typepayment;
/**
@ -83,18 +83,18 @@ class PaymentSalary extends CommonObject
public $num_payment;
/**
* @var int ID
*/
* @var int ID
*/
public $fk_bank;
/**
* @var int ID
*/
* @var int ID
*/
public $fk_user_author;
/**
* @var int ID
*/
* @var int ID
*/
public $fk_user_modif;
/**
@ -109,8 +109,8 @@ class PaymentSalary extends CommonObject
/**
* Create payment of salary into database.
* Use this->amounts to have list of lines for the payment
*
* Use this->amounts to have list of lines for the payment
*
* @param User $user User making payment
* @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more
* @return int <0 if KO, id of payment if OK
@ -121,13 +121,12 @@ class PaymentSalary extends CommonObject
$error = 0;
$now = dol_now();
$now = dol_now();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
// Validate parametres
if (!$this->datepaye)
{
if (!$this->datepaye) {
$this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
return -1;
}
@ -143,17 +142,16 @@ class PaymentSalary extends CommonObject
if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author;
if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
$totalamount = 0;
foreach ($this->amounts as $key => $value) // How payment is dispatch
{
$newvalue = price2num($value, 'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount);
$totalamount = 0;
foreach ($this->amounts as $key => $value) { // How payment is dispatch
$newvalue = price2num($value, 'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount);
// Check parameters
if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
// Check parameters
if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
$this->db->begin();
@ -190,13 +188,11 @@ class PaymentSalary extends CommonObject
$remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT');
if ($remaintopay == 0) {
$result = $contrib->set_paid($user);
}
else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
} else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
}
}
}
}
else {
} else {
$error++;
}
}
@ -205,9 +201,9 @@ class PaymentSalary extends CommonObject
if ($result < 0) $error++;
if ($totalamount != 0 && !$error) {
$this->amount = $totalamount;
$this->total = $totalamount; // deprecated
$this->db->commit();
$this->amount = $totalamount;
$this->total = $totalamount; // deprecated
$this->db->commit();
return $this->id;
} else {
$this->error = $this->db->error();
@ -362,15 +358,15 @@ class PaymentSalary extends CommonObject
$this->db->begin();
if ($this->bank_line > 0) {
$accline = new AccountLine($this->db);
if ($this->bank_line > 0) {
$accline = new AccountLine($this->db);
$accline->fetch($this->bank_line);
$result = $accline->delete();
if ($result < 0) {
$this->errors[] = $accline->error;
$error++;
}
}
}
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
@ -444,11 +440,11 @@ class PaymentSalary extends CommonObject
/**
* Initialise an instance with random values.
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @return void
* Initialise an instance with random values.
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @return void
*/
public function initAsSpecimen()
{
@ -469,92 +465,92 @@ class PaymentSalary extends CommonObject
}
/**
* Add record into bank for payment with links between this bank record and invoices of payment.
* All payment properties must have been set first like after a call to create().
*
* @param User $user Object of user making payment
* @param string $mode 'payment_sc'
* @param string $label Label to use in bank record
* @param int $accountid Id of bank account to do link with
* @param string $emetteur_nom Name of transmitter
* @param string $emetteur_banque Name of bank
* @return int <0 if KO, >0 if OK
*/
public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
{
global $conf;
/**
* Add record into bank for payment with links between this bank record and invoices of payment.
* All payment properties must have been set first like after a call to create().
*
* @param User $user Object of user making payment
* @param string $mode 'payment_sc'
* @param string $label Label to use in bank record
* @param int $accountid Id of bank account to do link with
* @param string $emetteur_nom Name of transmitter
* @param string $emetteur_banque Name of bank
* @return int <0 if KO, >0 if OK
*/
public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
{
global $conf;
// Clean data
$this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
$this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
$error = 0;
$error = 0;
if (!empty($conf->banque->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
if (!empty($conf->banque->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
$acc->fetch($accountid);
$acc = new Account($this->db);
$acc->fetch($accountid);
$total = $this->amount;
$total = $this->amount;
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
$this->datepaye,
$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
$label,
-$total,
$this->num_payment,
'',
$user,
$emetteur_nom,
$emetteur_banque,
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
$this->datepaye,
$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
$label,
-$total,
$this->num_payment,
'',
$user,
$emetteur_nom,
$emetteur_banque,
'',
$this->datev
);
);
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0) {
$result = $this->update_fk_bank($bank_line_id);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0) {
$result = $this->update_fk_bank($bank_line_id);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
$url = '';
if ($mode == 'payment_salary') $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
}
// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
$url = '';
if ($mode == 'payment_salary') $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
}
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
$linkaddedforthirdparty = array();
foreach ($this->amounts as $key => $value) {
if ($mode == 'payment_salary') {
$salary = new Salary($this->db);
$salary->fetch($key);
$result = $acc->add_url_line($bank_line_id, $salary->id, DOL_URL_ROOT.'/salaries/card.php?id=', '('.$salary->label.')', 'salary');
if ($result <= 0) dol_print_error($this->db);
}
}
} else {
$this->error = $acc->error;
$error++;
}
}
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
$linkaddedforthirdparty = array();
foreach ($this->amounts as $key => $value) {
if ($mode == 'payment_salary') {
$salary = new Salary($this->db);
$salary->fetch($key);
$result = $acc->add_url_line($bank_line_id, $salary->id, DOL_URL_ROOT.'/salaries/card.php?id=', '('.$salary->label.')', 'salary');
if ($result <= 0) dol_print_error($this->db);
}
}
} else {
$this->error = $acc->error;
$error++;
}
}
if (!$error) {
return 1;
} else {
return -1;
}
}
if (!$error) {
return 1;
} else {
return -1;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

View File

@ -84,7 +84,7 @@ class SalariesStats extends Stats
$sql = "SELECT YEAR(datep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " GROUP BY dm DESC";
//$sql .= " WHERE ".$this->where;
//$sql .= " WHERE ".$this->where;
return $this->_getNbByYear($sql);
}
@ -102,7 +102,7 @@ class SalariesStats extends Stats
$sql = "SELECT MONTH(datep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " WHERE YEAR(datep) = ".$year;
//$sql .= " AND ".$this->where;
//$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
$sql .= $this->db->order('dm', 'DESC');

File diff suppressed because it is too large Load Diff

View File

@ -77,12 +77,10 @@ $search_account = GETPOST('search_account', 'int');
$filtre = GETPOST("filtre", 'restricthtml');
if (!GETPOST('search_type_id', 'int'))
{
if (!GETPOST('search_type_id', 'int')) {
$newfiltre = str_replace('filtre=', '', $filtre);
$filterarray = explode('-', $newfiltre);
foreach ($filterarray as $val)
{
foreach ($filterarray as $val) {
$part = explode(':', $val);
if ($part[0] == 's.fk_typepayment') $search_type_id = $part[1];
}
@ -100,15 +98,13 @@ $result = restrictedArea($user, 'salaries', '', '', '');
// Initialize array of search criterias
$search_all = GETPOST("search_all", 'alpha');
$search = array();
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array();
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
}
@ -128,14 +124,12 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
if (empty($reshook)) {
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
$search_ref = "";
$search_user = "";
$search_label = "";
@ -146,8 +140,7 @@ if (empty($reshook))
$search_type_id = "";
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
{
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
@ -158,8 +151,7 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
// Validate records
if (!$error && $massaction == 'buildsepa' && $permissiontoadd)
{
if (!$error && $massaction == 'buildsepa' && $permissiontoadd) {
$objecttmp = new $objectclass($db);
// TODO
@ -213,26 +205,22 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
$offset = 0;
}
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit)))
{
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
$num = $nbtotalofrecords;
} else {
if ($limit) $sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
exit;
}
@ -323,8 +311,7 @@ print '<td class="liste_titre left">';
$form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16);
print '</td>';
// Account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<td class="liste_titre">';
$form->select_comptes($search_account, 'search_account', 0, '', 1);
print '</td>';
@ -371,10 +358,8 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0;
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
{
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
{
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
}
}
@ -384,8 +369,7 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co
$i = 0;
$total = 0;
$totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num))
{
while ($i < ($limit ? min($num, $limit) : $num)) {
$obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen
@ -432,18 +416,15 @@ while ($i < ($limit ? min($num, $limit) : $num))
if (!$i) $totalarray['nbfield']++;
// Account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<td>';
if ($obj->fk_bank > 0)
{
if ($obj->fk_bank > 0) {
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->number = $obj->bnumber;
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
$accountstatic->account_number = $obj->account_number;
$accountingjournal = new AccountingJournal($db);
@ -472,8 +453,7 @@ while ($i < ($limit ? min($num, $limit) : $num))
print $hookmanager->resPrint;
// Action column
print '<td class="nowrap center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($object->id, $arrayofselected)) $selected = 1;
print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
@ -491,8 +471,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
// If no record found
if ($num == 0)
{
if ($num == 0) {
$colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';