Update field denormalized_lower_planned_end_date in contract table.

This commit is contained in:
ldestailleur 2025-10-09 18:16:57 +02:00
parent 9bc45a5e89
commit 05d0bba2a0
4 changed files with 83 additions and 16 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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

View file

@ -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.<br>Should be applied when using emailing module with > 99 mailings.<br>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 '<tr style="background:#f4f4f4;font-weight:bold"><td colspan="5">'.$section.'</td></tr>';
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 '<tr>';
print '<td>' . $option . '</td>';
print '<td>' . $info . '</td>';
print '<td>';
if ($tooltip) {
print $form->textwithpicto($info, $tooltip);
} else {
print $info;
}
print '</td>';
print '<td class="center"><a href="'.$url_test.'" title="Launch test on option '.$option.'">test</a>'.($value == 'test' ? ' (X)' : '').'</td>';
print '<td class="center"><a href="'.$url_confirmed.'" title="Launch confirmed on option '.$option.'">confirmed</a>'.($value == 'confirmed' ? ' (X)' : '').'</td>';
print '</tr>';
@ -301,8 +314,7 @@ print '</table>';
print '<br id="sectionresult">';
print '<table cellspacing="0" cellpadding="1" class="centpercent">';
print '<br>';
$conf->setValues($db);
@ -324,11 +336,18 @@ $oneoptionset = (GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_l
if ($ok && $oneoptionset) {
// Show wait message
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'<br><br></td></tr>';
print $langs->trans("PleaseBePatient").'<br><br>';
// Flush (some browser need a certain amount of data)
print str_repeat(' ', 1024);
ob_flush();
flush();
}
print '<table cellspacing="0" cellpadding="1" class="centpercent">';
// 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 '<tr><td colspan="2"><br>*** Update denormalized_lower_planned_end_date.</td></tr>';
$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 '<tr><td colspan="2"><br>*** Check fields into extra table structure match table of definition. If not add column into table</td></tr>';
print '<tr><td colspan="2"><br>*** Check that fields into the extra table structure match the table of definition. If not, add column into table</td></tr>';
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 '<br>';
print '<div class="center" style="padding-top: 10px"><a href="../index.php?mainmenu=home&leftmenu=home'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
print img_picto('', 'url', 'class="pictofixedwidth"');
print $langs->trans("GoToDolibarr");
print '</a></div>';
}