From 05d0bba2a0cc61e63c5dcff1b489b69cc7740f6e Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Thu, 9 Oct 2025 18:16:57 +0200 Subject: [PATCH] Update field denormalized_lower_planned_end_date in contract table. --- htdocs/contrat/class/contrat.class.php | 32 ++++++++++++---- htdocs/contrat/class/contratligne.class.php | 25 +++++++++++- htdocs/core/class/commonobjectline.class.php | 2 + htdocs/install/repair.php | 40 +++++++++++++++++--- 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 285fe5df739..2417a61ba8d 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1676,10 +1676,10 @@ class Contrat extends CommonObject } /** - * Mets a jour une ligne de contrat + * Update a contract line * - * @param int $rowid Id de la ligne de facture - * @param string $desc Description de la ligne + * @param int $rowid Id of contract line + * @param string $desc Description of line * @param float $pu Prix unitaire * @param float $qty Quantite * @param float $remise_percent Percentage discount of the line @@ -1701,7 +1701,7 @@ class Contrat extends CommonObject */ public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx = 0.0, $localtax2tx = 0.0, $date_start_real = '', $date_end_real = '', $price_base_type = 'HT', $info_bits = 0, $fk_fournprice = null, $pa_ht = 0, $array_options = array(), $fk_unit = null, $rang = 0) { - global $user, $conf, $langs, $mysoc; + global $user, $langs, $mysoc; $error = 0; @@ -1822,7 +1822,16 @@ class Contrat extends CommonObject } } - // TODO Update column llx_contrat.denormalized_lower_panned_end_date + // Update column llx_contrat.denormalized_lower_panned_end_date with next expiration date of an open contract + $sqltoupdatecontract = "UPDATE ".MAIN_DB_PREFIX."contrat as c"; + $sqltoupdatecontract .= " SET c.denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = ".((int) $this->id)." AND cd.statut = ".ContratLigne::STATUS_OPEN.")"; + $sqltoupdatecontract .= " WHERE c.rowid = ".((int) $this->id); + $resqltoupdatecontract = $this->db->query($sqltoupdatecontract); + if (!$resqltoupdatecontract) { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -1; + } if (empty($error)) { // Call trigger @@ -2763,7 +2772,6 @@ class Contrat extends CommonObject // Load contract $object = new Contrat($this->db); $object->fetch($obj->rowid); // fetch also lines - //$object->fetch_thirdparty(); if ($object->id <= 0) { $error++; @@ -2832,8 +2840,16 @@ class Contrat extends CommonObject if ($resqlupdate) { $contractlineprocessed[$obj->lid] = $object->ref; - // TODO Update column llx_contrat.denormalized_lower_panned_end_date - + // Update column llx_contrat.denormalized_lower_panned_end_date with next expiration date of an open contract + $sqltoupdatecontract = "UPDATE ".MAIN_DB_PREFIX."contrat as c"; + $sqltoupdatecontract .= " SET c.denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = ".((int) $object->id)." AND cd.statut = ".ContratLigne::STATUS_OPEN.")"; + $sqltoupdatecontract .= " WHERE c.rowid = ".((int) $object->id); + $resqltoupdatecontract = $this->db->query($sqltoupdatecontract); + if (!$resqltoupdatecontract) { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -1; + } $actioncode = 'RENEW_CONTRACT'; $now = dol_now(); diff --git a/htdocs/contrat/class/contratligne.class.php b/htdocs/contrat/class/contratligne.class.php index e24726cc116..18c36bcc622 100644 --- a/htdocs/contrat/class/contratligne.class.php +++ b/htdocs/contrat/class/contratligne.class.php @@ -915,13 +915,14 @@ class ContratLigne extends CommonObjectLine $this->db->begin(); $this->statut = ContratLigne::STATUS_OPEN; + $this->status = ContratLigne::STATUS_OPEN; $this->date_start_real = $date; $this->date_end = $date_end; $this->fk_user_ouverture = $user->id; $this->date_end_real = null; $this->commentaire = $comment; - $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".((int) $this->statut).","; + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".((int) $this->status).","; $sql .= " date_ouverture = ".(dol_strlen((string) $this->date_start_real) != 0 ? "'".$this->db->idate($this->date_start_real)."'" : "null").","; if ($date_end >= 0) { $sql .= " date_fin_validite = ".(dol_strlen($this->date_end) != 0 ? "'".$this->db->idate($this->date_end)."'" : "null").","; @@ -935,7 +936,16 @@ class ContratLigne extends CommonObjectLine $resql = $this->db->query($sql); if ($resql) { if ($date_end >= 0) { - // TODO Update column llx_contrat.denormalized_lower_panned_end_date + // Update column llx_contrat.denormalized_lower_panned_end_date with next expiration date of an open contract + $sqltoupdatecontract = "UPDATE ".MAIN_DB_PREFIX."contrat as c"; + $sqltoupdatecontract .= " SET c.denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = ".((int) $this->fk_contrat)." AND cd.statut = ".ContratLigne::STATUS_OPEN.")"; + $sqltoupdatecontract .= " WHERE c.rowid = ".((int) $this->fk_contrat); + $resqltoupdatecontract = $this->db->query($sqltoupdatecontract); + if (!$resqltoupdatecontract) { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -1; + } } // Call trigger @@ -991,6 +1001,17 @@ class ContratLigne extends CommonObjectLine $resql = $this->db->query($sql); if ($resql) { + // Update column llx_contrat.denormalized_lower_panned_end_date with next expiration date of an open contract + $sqltoupdatecontract = "UPDATE ".MAIN_DB_PREFIX."contrat as c"; + $sqltoupdatecontract .= " SET c.denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = ".((int) $this->fk_contrat)." AND cd.statut = ".ContratLigne::STATUS_OPEN.")"; + $sqltoupdatecontract .= " WHERE c.rowid = ".((int) $this->fk_contrat); + $resqltoupdatecontract = $this->db->query($sqltoupdatecontract); + if (!$resqltoupdatecontract) { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -1; + } + if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINECONTRACT_CLOSE', $user); diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 3596c294d67..82b3802e680 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -24,6 +24,8 @@ * \brief File of the superclass of classes of lines of business objects (invoice, contract, proposal, orders, etc. ...) */ +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + /** * Parent class for class inheritance lines of business objects diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 3c4cc83700d..5ad0d3577aa 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -56,6 +56,7 @@ if (file_exists($conffile)) { require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; include_once $dolibarr_main_document_root.'/core/lib/images.lib.php'; require_once $dolibarr_main_document_root.'/core/class/extrafields.class.php'; +require_once $dolibarr_main_document_root.'/core/class/html.form.class.php'; require_once 'lib/repair.lib.php'; $ok = 0; @@ -94,6 +95,8 @@ if (!is_object($conf)) { * View */ +$form = new Form($db); + pHeader($langs->trans("Repair"), "upgrade2", GETPOST('action', 'aZ09')); // Action to launch the repair script @@ -219,7 +222,8 @@ $sections = [ ], [ 'name' => 'repair_mailing_path', - 'info' => 'Repair path of mailing files.
Should be applied when using emailing module with > 99 mailings.
In that case, please also set MAILING_USE_NEW_PATH_FOR_FILES.' + 'info' => 'Repair path of mailing files', + 'tooltip' => 'Should be applied when using emailing module with > 99 mailings. In that case, please also set MAILING_USE_NEW_PATH_FOR_FILES.' ] ], 'Clean tables and data' => [ @@ -280,18 +284,27 @@ $sections = [ ] ]; +$conf->use_javascript_ajax = 1; + foreach ($sections as $section => $options) { print ''.$section.''; foreach ($options as $opt) { $option = $opt['name']; $info = $opt['info']; + $tooltip = empty($opt['tooltip']) ? '' : $opt['tooltip']; $value = GETPOST($option, 'alpha') ? GETPOST($option, 'alpha') : 'undefined'; // Generate links with the right option and value $url_test = $_SERVER['PHP_SELF'].'?'.$option.'=test'; $url_confirmed = $_SERVER['PHP_SELF'].'?'.$option.'=confirmed'; print ''; print '' . $option . ''; - print '' . $info . ''; + print ''; + if ($tooltip) { + print $form->textwithpicto($info, $tooltip); + } else { + print $info; + } + print ''; print 'test'.($value == 'test' ? ' (X)' : '').''; print 'confirmed'.($value == 'confirmed' ? ' (X)' : '').''; print ''; @@ -301,8 +314,7 @@ print ''; print '
'; - -print ''; +print '
'; $conf->setValues($db); @@ -324,11 +336,18 @@ $oneoptionset = (GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_l if ($ok && $oneoptionset) { // Show wait message - print ''; + print $langs->trans("PleaseBePatient").'

'; + + // Flush (some browser need a certain amount of data) + print str_repeat(' ', 1024); + ob_flush(); flush(); } + +print '
'.$langs->trans("PleaseBePatient").'

'; + // run_sql: Run repair SQL file if ($ok && GETPOST('standard', 'alpha')) { $dir = "mysql/migration/"; @@ -371,6 +390,13 @@ if ($ok && GETPOST('standard', 'alpha')) { // sync_extrafields: Search list of fields declared and list of fields created into databases, then create fields missing if ($ok && GETPOST('standard', 'alpha')) { + require_once DOL_DOCUMENT_ROOT.'/contrat/class/contratligne.class.php'; + + print ''; + $sqltoupdatecontract = "UPDATE ".MAIN_DB_PREFIX."contrat as c"; + $sqltoupdatecontract .= " SET c.denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.statut = ".ContratLigne::STATUS_OPEN.")"; + $resqltoupdatecontract = $db->query($sqltoupdatecontract); + $extrafields = new ExtraFields($db); // List of tables that has an extrafield table @@ -385,7 +411,7 @@ if ($ok && GETPOST('standard', 'alpha')) { 'adherent_type' => 'adherent_type', 'user' => 'user', 'partnership' => 'partnership', 'projet' => 'projet', 'projet_task' => 'projet_task', 'ticket' => 'ticket'); //$listofmodulesextra = array('fichinter'=>'fichinter'); - print ''; + print ''; foreach ($listofmodulesextra as $tablename => $elementtype) { // Get list of fields $tableextra = MAIN_DB_PREFIX.$tablename.'_extrafields'; @@ -2148,7 +2174,9 @@ if (empty($actiondone)) { } if ($oneoptionset) { + print '
'; print '
'; + print img_picto('', 'url', 'class="pictofixedwidth"'); print $langs->trans("GoToDolibarr"); print '
'; }

*** Update denormalized_lower_planned_end_date.

*** Check fields into extra table structure match table of definition. If not add column into table

*** Check that fields into the extra table structure match the table of definition. If not, add column into table