diff --git a/dev/tools/phan/config_fixer.php b/dev/tools/phan/config_fixer.php index e9a0fa36763..521cbcbedbf 100644 --- a/dev/tools/phan/config_fixer.php +++ b/dev/tools/phan/config_fixer.php @@ -15,7 +15,8 @@ $config = include __DIR__.DIRECTORY_SEPARATOR."config.php"; //require_once __DIR__.'/plugins/UrlEncodeStringifyFixer.php'; //require_once __DIR__.'/plugins/SelectDateFixer.php'; //require_once __DIR__.'/plugins/setPageOrientationFixer.php'; -require_once __DIR__.'/plugins/textwithpictoFixer.php'; +//require_once __DIR__.'/plugins/textwithpictoFixer.php'; +require_once __DIR__.'/plugins/ifsqlFixer.php'; //require_once __DIR__.'/plugins/MultiCellFixer.php'; //require_once __DIR__.'/plugins/setAutoPageBreakFixer.php'; //require_once __DIR__.'/plugins/CellFixer.php'; diff --git a/dev/tools/phan/plugins/ifsqlFixer.php b/dev/tools/phan/plugins/ifsqlFixer.php new file mode 100644 index 00000000000..ba97b719c24 --- /dev/null +++ b/dev/tools/phan/plugins/ifsqlFixer.php @@ -0,0 +1,177 @@ + + * + * For 'price()', replace $form parameter that is '' with 0. + */ + +declare(strict_types=1); + +use ast\flags; +use Microsoft\PhpParser\Node\Expression\CallExpression; +use Microsoft\PhpParser\Node\QualifiedName; +use Phan\AST\TolerantASTConverter\NodeUtils; +use Phan\CodeBase; +use Phan\IssueInstance; +use Phan\Library\FileCacheEntry; +use Phan\Plugin\Internal\IssueFixingPlugin\FileEdit; +use Phan\Plugin\Internal\IssueFixingPlugin\FileEditSet; +use Phan\Plugin\Internal\IssueFixingPlugin\IssueFixer; +use Microsoft\PhpParser\Node\Expression\ArgumentExpression; +use Microsoft\PhpParser\Node\DelimitedList\ArgumentExpressionList; +use Microsoft\PhpParser\Node\StringLiteral; +use Microsoft\PhpParser\Node\NumericLiteral; +use Microsoft\PhpParser\Node\ReservedWord; +use Microsoft\PhpParser\Token; + +/** + * This is a prototype, there are various features it does not implement. + */ + +call_user_func(static function (): void { + /** + * @param $code_base @unused-param + * @return ?FileEditSet a representation of the edit to make to replace a call to a function alias with a call to the original function + */ + $fix = static function (CodeBase $code_base, FileCacheEntry $contents, IssueInstance $instance): ?FileEditSet { + + // Argument {INDEX} (${PARAMETER}) is {CODE} of type {TYPE}{DETAILS} but + // {FUNCTIONLIKE} takes {TYPE}{DETAILS} defined at {FILE}:{LINE} (the inferred real argument type has nothing in common with the parameter's phpdoc type) + + //htdocs\supplier_proposal\card.php:1705 PhanTypeMismatchArgumentProbablyReal Argument 3 ($h) is '' of type '' but \Form::selectDate() takes int (no real type) defined at htdocs\core\class\html.form.class.php:6799 (the inferred real argument type has nothing in common with the parameter's phpdoc type) + //htdocs\supplier_proposal\card.php:1705 PhanTypeMismatchArgumentProbablyReal Argument 4 ($m) is '' of type '' but \Form::selectDate() takes int (no real type) defined at htdocs\core\class\html.form.class.php:6799 (the inferred real argument type has nothing in common with the parameter's phpdoc type) + // var_dump($instance->getTemplateParameters()); + $argument_index = (string) $instance->getTemplateParameters()[0]; + $argument_name = (string) $instance->getTemplateParameters()[1]; + $argument_code = (string) $instance->getTemplateParameters()[2]; + $argument_type = (string) $instance->getTemplateParameters()[3]; + $functionlike = (string) $instance->getTemplateParameters()[4]; + $functiontype = (string) $instance->getTemplateParameters()[5]; + + $expected_functionlike = "\\DoliDB::ifsql()"; + $expected_name = "ifsql"; + if ($functionlike !== $expected_functionlike) { + //print "$functionlike != '$expected_functionlike'".PHP_EOL; + return null; + } + + $toBoolReplaceArray = array("0" => "'0'","1" => "'1'","-1" => "'-1'"); + // Check if we fix any of this + if ( + (in_array($argument_name, ['resok','resko']) && in_array($argument_code, array_keys($toBoolReplaceArray))) + //|| ($argument_name === 'm' && $argument_code === "''") + //|| ($argument_name === 'empty' && $argument_code === "''") + ) { + $replacement = $toBoolReplaceArray[$argument_code]; + $argIdx = ($argument_index - 1) * 2; + $expectedStringValue = $argument_code; + } else { + print "ARG$argument_index:$argument_name CODE:$argument_name".PHP_EOL; + return null; + } + + // At this point we established that the notification + // matches some we fix. + + $line = $instance->getLine(); + + $edits = []; + foreach ($contents->getNodesAtLine($line) as $node) { + if (!$node instanceof ArgumentExpressionList) { + continue; + } + $arguments = $node->children; + if (count($arguments) <= $argIdx) { + // print "Arg Count is ".count($arguments)." - Skip $instance".PHP_EOL; + continue; + } + + $is_actual_call = $node->parent instanceof CallExpression; + if (!$is_actual_call) { + // print "Not actual call - Skip $instance".PHP_EOL; + continue; + } + + print "Actual call - $instance".PHP_EOL; + $callable = $node->parent; + + $callableExpression = $callable->callableExpression; + + if ($callableExpression instanceof Microsoft\PhpParser\Node\QualifiedName) { + $actual_name = $callableExpression->getResolvedName(); + } elseif ($callableExpression instanceof Microsoft\PhpParser\Node\Expression\MemberAccessExpression) { + $memberNameToken = $callableExpression->memberName; + $actual_name = (new NodeUtils($contents->getContents()))->tokenToString($memberNameToken); + } else { + print "Callable expression is ".get_class($callableExpression)."- Skip $instance".PHP_EOL; + continue; + } + + if ((string) $actual_name !== (string) $expected_name) { + // print "Name unexpected '$actual_name'!='$expected_name' - Skip $instance".PHP_EOL; + continue; + } + + foreach ($arguments as $i => $argument) { + if ($argument instanceof ArgumentExpression) { + // print "Type$i: ".get_class($argument->expression).PHP_EOL; + } + } + + $fieldValue = null; + + + $arg = $arguments[$argIdx]; + + if ( + $arg instanceof ArgumentExpression + && $arg->expression instanceof NumericLiteral + ) { + // Get the string value of the NumericLiteral + $fieldValue = (string) $arg->expression; + //print "Field is '$fieldValue'".PHP_EOL; + } elseif ($arg instanceof ArgumentExpression && $arg->expression instanceof ReservedWord) { + $child = $arg->expression->children; + if (!$child instanceof Token) { + continue; + } + $token_str = (new NodeUtils($contents->getContents()))->tokenToString($child); + print "$token_str KIND:".($child->kind ?? 'no kind')." ".get_class($child).PHP_EOL; + + if ($token_str !== 'null') { + continue; + } + + $fieldValue = ''; // Fake empty + } else { + // print "Expression is not expected type ".get_class($arg)."/".get_class($arg->expression)."- Skip $instance".PHP_EOL; + continue; + } + + if ($fieldValue !== $expectedStringValue) { + // print "Not replacing '$argument_name' which is '$fieldValue'/".get_class($arg)."/".get_class($arg->expression)."- Skip $instance".PHP_EOL; + continue; + } + + print "Fixture elem on $line - $actual_name(...'$fieldValue'...) - $instance".PHP_EOL; + + + + // Get the first argument (delimiter) + $argument_to_replace = $arg; + + $arg_start_pos = $argument_to_replace->getStartPosition(); + $arg_end_pos = $argument_to_replace->getEndPosition(); + + // Set edit instruction + $edits[] = new FileEdit($arg_start_pos, $arg_end_pos, $replacement); + } + if ($edits) { + return new FileEditSet($edits); + } + return null; + }; + IssueFixer::registerFixerClosure( + 'PhanTypeMismatchArgument', + $fix + ); +}); diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index e1934a31b0e..d2217e62654 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -5,6 +5,7 @@ * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 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 @@ -429,10 +430,10 @@ if ($resql) { $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y; $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt'); - print ''; - print price($row[2*$i - 2]); + print ''; + print price($row[2 * $i - 2]); // Add link to make binding - if (!empty(price2num($row[2*$i - 2])) || !empty($row[2*$i - 1])) { + if (!empty(price2num($row[2 * $i - 2])) || !empty($row[2 * $i - 1])) { print ''; print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"'); print ''; @@ -672,7 +673,7 @@ if (getDolGlobalString('SHOW_TOTAL_OF_PREVIOUS_LISTS_IN_LIN_PAGE')) { // This pa " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", // TODO This is bugged, we must use the percent for the invoice and fd.situation_percent is cumulated percent ! " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))" ).")", - 0 + '0' ).") AS month".str_pad((string) $j, 2, '0', STR_PAD_LEFT).","; } $sql .= " SUM(".$db->ifsql( @@ -694,7 +695,7 @@ if (getDolGlobalString('SHOW_TOTAL_OF_PREVIOUS_LISTS_IN_LIN_PAGE')) { // This pa " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))", " (fd.total_ht - (fd.buy_price_ht * fd.qty))" ).")", - 0 + '0' ).") AS month".str_pad((string) $j, 2, '0', STR_PAD_LEFT).","; } $sql .= " SUM(".$db->ifsql( diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index 13c6119e9f8..44eb8af5724 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2017 Laurent Destailleur * Copyright (C) 2018-2024 Alexandre Spangaro * Copyright (C) 2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Jose MARTINEZ * * This program is free software; you can redistribute it and/or modify @@ -713,7 +713,7 @@ class Asset extends CommonObject */ $sql = "SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht"; - $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0) . " AS bookkeeping"; + $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', '1', '0') . " AS bookkeeping"; $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad"; $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid"; $sql .= " WHERE ad.fk_asset = " . (int) $this->id; diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index be2f81dc20f..1906560455c 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2019 Nicolas ZABOURI - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Alexandre Spangaro * Copyright (C) 2024 Frédéric France * @@ -328,11 +328,11 @@ print '
'; // Last modified contracts $sql = 'SELECT '; -$sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,'; -$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,'; -$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,'; -$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,'; -$sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,'; +$sql .= " sum(".$db->ifsql("cd.statut=0", '1', '0').') as nb_initial,'; +$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", '1', '0').') as nb_running,'; +$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", '1', '0').') as nb_expired,'; +$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", '1', '0').') as nb_late,'; +$sql .= " sum(".$db->ifsql("cd.statut=5", '1', '0').') as nb_closed,'; $sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut,"; $sql .= " s.nom as name, s.name_alias, s.logo, s.rowid as socid, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,"; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 5dc7e793af9..52557b35668 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -9,7 +9,7 @@ * Copyright (C) 2016-2018 Ferran Marcet * Copyright (C) 2019 Nicolas Zabouri * Copyright (C) 2021-2024 Alexandre Spangaro - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * Copyright (C) 2024 Benjamin Falière * @@ -325,11 +325,11 @@ $sql .= " state.code_departement as state_code, state.nom as state_name,"; // TODO Add a denormalized field "denormalized_lower_planned_end_date" so we can remove the HAVING and then, // remove completely the SUM and GROUP BY (faster). Status of each service can be read into the loop that build the list. $sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,"; // lowest expiration date among open service lines -$sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,'; -$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,'; -$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,'; -$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,'; -$sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed'; +$sql .= " SUM(".$db->ifsql("cd.statut=0", '1', '0').') as nb_initial,'; +$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", '1', '0').') as nb_running,'; +$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", '1', '0').') as nb_expired,'; +$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", '1', '0').') as nb_late,'; +$sql .= " SUM(".$db->ifsql("cd.statut=5", '1', '0').') as nb_closed'; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 4228c0a499f..c536e435c3a 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -5,7 +5,7 @@ * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2017 Charlie Benke * Copyright (C) 2017 ATM-CONSULTING - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -441,12 +441,12 @@ function getNumberInvoicesPieChart($mode) $amount_mode = (getDolGlobalInt('FACTURE_VALIDATED_IN_AMOUNT') == 1); $sql = "SELECT"; - $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as late30"; - $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as late15"; - $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as latenow"; - $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as notlatenow"; - $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd15, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as notlate15"; - $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, 0).") as notlate30"; + $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late30"; + $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late15"; + $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as latenow"; + $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlatenow"; + $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd15, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate15"; + $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate30"; if ($mode == 'customers') { $element = 'invoice'; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -569,7 +569,9 @@ function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0) $result = ''; if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) { - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); $tmpinvoice = new Facture($db); @@ -721,7 +723,9 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0) $result = ''; if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) { - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); $facturesupplierstatic = new FactureFournisseur($db); @@ -854,7 +858,9 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0) function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0) { global $conf, $db, $langs, $user; - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datec,"; $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -963,7 +969,9 @@ function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0) function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0) { global $conf, $db, $langs, $user; - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.datec,"; $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; @@ -1081,7 +1089,9 @@ function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0) $result = ''; if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) { - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $tmpinvoice = new Facture($db); $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms"; @@ -1271,7 +1281,9 @@ function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0) $result = ''; if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) { - if ($user->socid > 0) $socid = $user->socid; + if ($user->socid > 0) { + $socid = $user->socid; + } $facstatic = new FactureFournisseur($db); $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye"; diff --git a/htdocs/product/stats/contrat.php b/htdocs/product/stats/contrat.php index 593fe5c25aa..7903b1663fd 100644 --- a/htdocs/product/stats/contrat.php +++ b/htdocs/product/stats/contrat.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 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 @@ -139,10 +140,10 @@ if ($id > 0 || !empty($ref)) { $now = dol_now(); $sql = "SELECT"; - $sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,'; - $sql .= " sum(".$db->ifsql("cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now)."'", 1, 0).") as nb_running,"; - $sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite <= '".$db->idate($now)."')", 1, 0).') as nb_late,'; - $sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,'; + $sql .= " sum(".$db->ifsql("cd.statut=0", '1', '0').') as nb_initial,'; + $sql .= " sum(".$db->ifsql("cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now)."'", '1', '0').") as nb_running,"; + $sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite <= '".$db->idate($now)."')", '1', '0').') as nb_late,'; + $sql .= " sum(".$db->ifsql("cd.statut=5", '1', '0').') as nb_closed,'; $sql .= " c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,"; $sql .= " s.nom as name, s.rowid as socid, s.code_client"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; diff --git a/htdocs/product/stats/mo.php b/htdocs/product/stats/mo.php index 23a987a6243..6772312c4f1 100644 --- a/htdocs/product/stats/mo.php +++ b/htdocs/product/stats/mo.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2023 Gauthier VERDOL * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 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 @@ -150,10 +151,10 @@ if ($id > 0 || !empty($ref)) { $now = dol_now(); $sql = "SELECT"; - $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,'; - $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", 0).') as nb_consumed,'; - $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,'; - $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", 0).') as nb_produced,'; + $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", '0').') as nb_toconsume,'; + $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", '0').') as nb_consumed,'; + $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", '0').') as nb_toproduce,'; + $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", '0').') as nb_produced,'; $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status"; //$sql .= " s.nom as name, s.rowid as socid, s.code_client"; $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; diff --git a/htdocs/product/stock/stats/mo.php b/htdocs/product/stock/stats/mo.php index 9a87fa83783..b1a3477871b 100644 --- a/htdocs/product/stock/stats/mo.php +++ b/htdocs/product/stock/stats/mo.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2023 Gauthier VERDOL * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 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 @@ -176,9 +177,9 @@ if ($id > 0 || !empty($ref)) { $sql = "SELECT"; // $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,'; - $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", 0).') as nb_consumed,'; + $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", '0').') as nb_consumed,'; // $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,'; - $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", 0).') as nb_produced,'; + $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", '0').') as nb_produced,'; $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status"; //$sql .= " s.nom as name, s.rowid as socid, s.code_client"; $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index ba6f4f83ca5..d76e3a605f4 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1845,9 +1845,9 @@ class Task extends CommonObjectLine $sql .= " MIN(t.element_datehour) as min_date,"; $sql .= " MAX(t.element_datehour) as max_date,"; $sql .= " SUM(t.element_duration) as total_duration,"; - $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as total_amount,"; + $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", '0', "t.thm").") as total_amount,"; $sql .= " COUNT(t.rowid) as nblines,"; - $sql .= " SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; + $sql .= " SUM(".$this->db->ifsql("t.thm IS NULL", '1', '0').") as nblinesnull"; $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t"; $sql .= " WHERE t.elementtype='task'"; if ($morewherefilter) { @@ -1899,7 +1899,7 @@ class Task extends CommonObjectLine $sql = "SELECT"; $sql .= " SUM(t.element_duration) as nbseconds,"; - $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", 0, "t.thm").") as amount, SUM(".$this->db->ifsql("t.thm IS NULL", 1, 0).") as nblinesnull"; + $sql .= " SUM(t.element_duration / 3600 * ".$this->db->ifsql("t.thm IS NULL", '0', "t.thm").") as amount, SUM(".$this->db->ifsql("t.thm IS NULL", '1', '0').") as nblinesnull"; $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t"; $sql .= " WHERE t.elementtype='task' AND t.fk_element = ".((int) $id); if (is_object($fuser) && $fuser->id > 0) {