From 664ba283bc3b7a6fafc8114aa073bbb00e0de104 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 6 Oct 2022 09:49:17 +0200 Subject: [PATCH 01/13] fix/feat: on CronJob sendEmailsRemindersOnInvoiceDueDate use billing contact email if exists --- htdocs/compta/facture/class/facture.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 67d5568e438..b781cc15961 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5530,7 +5530,16 @@ class Facture extends CommonInvoice $res = $tmpinvoice->fetch_thirdparty(); $recipient = $tmpinvoice->thirdparty; if ($res > 0) { - if (!empty($recipient->email)) { + $tmparraycontact = $tmpinvoice->liste_contact(-1, 'external', 0, 'BILLING'); + if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { + foreach ($tmparraycontact as $data_email) { + if (!empty($data_email['email'])) { + $to = $data_email['email']; + break; + } + } + } + if (empty($to) && !empty($recipient->email)) { $to = $recipient->email; } else { $errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user."; From d597eb820299994496435d0293557f6b1c7a5182 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 7 Oct 2022 12:02:53 +0200 Subject: [PATCH 02/13] NEW: Manage Position (Rank) on Contract Lines --- htdocs/contrat/card.php | 105 ++++++---- htdocs/contrat/class/api_contracts.class.php | 24 +-- htdocs/contrat/class/contrat.class.php | 189 ++++++++++-------- htdocs/core/ajax/row.php | 4 +- htdocs/install/upgrade2.php | 66 ++++++ htdocs/langs/en_US/install.lang | 1 + .../template/class/myobject.class.php | 2 +- .../modulebuilder/template/myobject_card.php | 10 +- 8 files changed, 263 insertions(+), 138 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 93d33565143..9a81c1ccac4 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -97,7 +97,8 @@ $extralabelslines = $extrafields->fetch_name_optionals_label($object->table_elem $permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php - +$permissiontoadd = $user->rights->contrat->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontoedit = $permissiontoadd; $error = 0; @@ -138,6 +139,8 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once + if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { $result = $object->active_line($user, GETPOST('ligne', 'int'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); @@ -350,7 +353,8 @@ if (empty($reshook)) { $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $array_options, - $lines[$i]->fk_unit + $lines[$i]->fk_unit, + $num+1 ); if ($result < 0) { @@ -402,6 +406,8 @@ if (empty($reshook)) { $price_ttc = ''; $price_ttc_devise = ''; + $rang = count($object->lines) + 1; + if (GETPOST('price_ht') !== '') { $price_ht = price2num(GETPOST('price_ht'), 'MU', 2); } @@ -609,7 +615,8 @@ if (empty($reshook)) { $fk_fournprice, $pa_ht, $array_options, - $fk_unit + $fk_unit, + $rang ); } @@ -692,10 +699,10 @@ if (empty($reshook)) { if (!$error) { if ($date_start_real_update == '') { - $date_start_real_update = $objectline->date_ouverture; + $date_start_real_update = $objectline->date_start_real; } if ($date_end_real_update == '') { - $date_end_real_update = $objectline->date_cloture; + $date_end_real_update = $objectline->date_end_real; } $vat_rate = GETPOST('eltva_tx'); @@ -739,13 +746,14 @@ if (empty($reshook)) { $objectline->vat_src_code = $vat_src_code; $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0; $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0; - $objectline->date_ouverture_prevue = $date_start_update; - $objectline->date_ouverture = $date_start_real_update; - $objectline->date_fin_validite = $date_end_update; - $objectline->date_cloture = $date_end_real_update; + $objectline->date_start = $date_start_update; + $objectline->date_start_real = $date_start_real_update; + $objectline->date_end = $date_end_update; + $objectline->date_end_real = $date_end_real_update; $objectline->fk_user_cloture = $user->id; $objectline->fk_fournprice = $fk_fournprice; $objectline->pa_ht = $pa_ht; + $objectline->rang = $objectline->rang; if ($fk_unit > 0) { $objectline->fk_unit = GETPOST('unit'); @@ -1482,9 +1490,11 @@ if ($action == 'create') { // Title line for service $cursorline = 1; - print '
'; + + + print '
'; while ($cursorline <= $nbofservices) { - print '
'; + print '
'; print '
'; print ''; print ''; @@ -1493,15 +1503,16 @@ if ($action == 'create') { // Area with common detail of line print '
'; - print ''; + print '
'; $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,"; $sql .= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,"; - $sql .= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,"; - $sql .= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,"; + $sql .= " cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,"; + $sql .= " cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,"; $sql .= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,"; $sql .= " cd.fk_unit,"; $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity, p.tosell, p.tobuy, p.tobatch"; + $sql .= " ,cd.rang"; $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql .= " WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id); @@ -1510,6 +1521,8 @@ if ($action == 'create') { if ($result) { $total = 0; + $objp = $db->fetch_object($result); + print ''; print ''; print ''; @@ -1525,10 +1538,28 @@ if ($action == 'create') { if (isModEnabled('margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) { print ''; } - print ''; + // + + if ($nbofservices > 1 && $conf->browser->layout != 'phone' && !empty($user->rights->contrat->creer)) { + print ''; + } else { + print ''; + } + print "\n"; - $objp = $db->fetch_object($result); + // Line in view mode if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) { @@ -1633,10 +1664,10 @@ if ($action == 'create') { // Date planned print $langs->trans("DateStartPlanned").': '; - if ($objp->date_debut) { - print dol_print_date($db->jdate($objp->date_debut), 'day'); + if ($objp->date_start) { + print dol_print_date($db->jdate($objp->date_start), 'day'); // Warning si date prevu passee et pas en service - if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { + if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) { $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); @@ -1646,9 +1677,9 @@ if ($action == 'create') { } print '  -  '; print $langs->trans("DateEndPlanned").': '; - if ($objp->date_fin) { - print dol_print_date($db->jdate($objp->date_fin), 'day'); - if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { + if ($objp->date_end) { + print dol_print_date($db->jdate($objp->date_end), 'day'); + if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) { $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); @@ -1760,9 +1791,9 @@ if ($action == 'create') { print ''; print ''; print ''; @@ -1882,26 +1913,26 @@ if ($action == 'create') { print '
'.$langs->trans("ServiceNb", $cursorline).''.$langs->trans("VAT").''.$langs->trans("BuyingPrice").' '; + if ($cursorline > 1) { + print 'rowid.'">'; + echo img_up('default', 0, 'imgupforline'); + print ''; + } + if ($cursorline < $nbofservices) { + print 'rowid.'">'; + echo img_down('default', 0, 'imgdownforline'); + print ''; + } + print ' sss
'; print $langs->trans("DateStartPlanned").' '; - print $form->selectDate($db->jdate($objp->date_debut), "date_start_update", $usehm, $usehm, ($db->jdate($objp->date_debut) > 0 ? 0 : 1), "update"); + print $form->selectDate($db->jdate($objp->date_start), "date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1), "update"); print '   '.$langs->trans("DateEndPlanned").' '; - print $form->selectDate($db->jdate($objp->date_fin), "date_end_update", $usehm, $usehm, ($db->jdate($objp->date_fin) > 0 ? 0 : 1), "update"); + print $form->selectDate($db->jdate($objp->date_end), "date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1), "update"); print '
'; // Si pas encore active - if (!$objp->date_debut_reelle) { + if (!$objp->date_start_real) { print $langs->trans("DateStartReal").': '; - if ($objp->date_debut_reelle) { - print dol_print_date($db->jdate($objp->date_debut_reelle), 'day'); + if ($objp->date_start_real) { + print dol_print_date($db->jdate($objp->date_start_real), 'day'); } else { print $langs->trans("ContractStatusNotRunning"); } } // Si active et en cours - if ($objp->date_debut_reelle && !$objp->date_fin_reelle) { + if ($objp->date_start_real && !$objp->date_end_real) { print $langs->trans("DateStartReal").': '; - print dol_print_date($db->jdate($objp->date_debut_reelle), 'day'); + print dol_print_date($db->jdate($objp->date_start_real), 'day'); } // Si desactive - if ($objp->date_debut_reelle && $objp->date_fin_reelle) { + if ($objp->date_start_real && $objp->date_end_real) { print $langs->trans("DateStartReal").': '; - print dol_print_date($db->jdate($objp->date_debut_reelle), 'day'); + print dol_print_date($db->jdate($objp->date_start_real), 'day'); print '  -  '; print $langs->trans("DateEndReal").': '; - print dol_print_date($db->jdate($objp->date_fin_reelle), 'day'); + print dol_print_date($db->jdate($objp->date_end_real), 'day'); } if (!empty($objp->comment)) { print "  -  ".$objp->comment; @@ -1922,14 +1953,14 @@ if ($action == 'create') { print ''; // Definie date debut et fin par defaut - $dateactstart = $objp->date_debut; + $dateactstart = $objp->date_start; if (GETPOST('remonth')) { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); } elseif (!$dateactstart) { $dateactstart = time(); } - $dateactend = $objp->date_fin; + $dateactend = $objp->date_end; if (GETPOST('endmonth')) { $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); } elseif (!$dateactend) { @@ -1978,14 +2009,14 @@ if ($action == 'create') { print '
'; // Definie date debut et fin par defaut - $dateactstart = $objp->date_debut_reelle; + $dateactstart = $objp->date_start_real; if (GETPOST('remonth')) { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); } elseif (!$dateactstart) { $dateactstart = time(); } - $dateactend = $objp->date_fin_reelle; + $dateactend = $objp->date_end_real; if (GETPOST('endmonth')) { $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); } elseif (!$dateactend) { @@ -2004,7 +2035,7 @@ if ($action == 'create') { if ($objp->statut >= 4) { if ($objp->statut == 4) { print $langs->trans("DateEndReal").' '; - print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_fin_reelle > 0 ? 0 : 1), "closeline", 1, 1); + print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1), "closeline", 1, 1); } } print ''; diff --git a/htdocs/contrat/class/api_contracts.class.php b/htdocs/contrat/class/api_contracts.class.php index ea228550cae..f38fa4758d9 100644 --- a/htdocs/contrat/class/api_contracts.class.php +++ b/htdocs/contrat/class/api_contracts.class.php @@ -290,8 +290,8 @@ class Contracts extends DolibarrApi $request_data->localtax2_tx, $request_data->fk_product, $request_data->remise_percent, - $request_data->date_start, // date_start = date planned start, date ouverture = date_start_real - $request_data->date_end, // date_end = date planned end, date_cloture = date_end_real + $request_data->date_start, + $request_data->date_end, $request_data->price_base_type ? $request_data->price_base_type : 'HT', $request_data->subprice_excl_tax, $request_data->info_bits, @@ -345,13 +345,13 @@ class Contracts extends DolibarrApi $request_data->subprice, $request_data->qty, $request_data->remise_percent, - $request_data->date_ouveture_prevue, - $request_data->date_fin_validite, + $request_data->date_start, + $request_data->date_end, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, - $request_data->date_ouverture, - $request_data->date_cloture, + $request_data->date_start_real, + $request_data->date_end_real, $request_data->price_base_type ? $request_data->price_base_type : 'HT', $request_data->info_bits, $request_data->fk_fourn_price, @@ -662,14 +662,10 @@ class Contracts extends DolibarrApi unset($object->address); - unset($object->date_ouverture_prevue); - unset($object->date_ouverture); - unset($object->date_fin_validite); - unset($object->date_cloture); - unset($object->date_debut_prevue); - unset($object->date_debut_reel); - unset($object->date_fin_prevue); - unset($object->date_fin_reel); + unset($object->date_start); + unset($object->date_start_real); + unset($object->date_end); + unset($object->date_end_real); unset($object->civility_id); return $object; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 2a8d1b815a7..497595a1be1 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -788,19 +788,22 @@ class Contrat extends CommonObject $sql .= " d.total_localtax2,"; $sql .= " d.total_ttc,"; $sql .= " d.info_bits, d.fk_product,"; - $sql .= " d.date_ouverture_prevue, d.date_ouverture,"; - $sql .= " d.date_fin_validite, d.date_cloture,"; + $sql .= " d.date_ouverture_prevue as date_start,"; + $sql .= " d.date_ouverture as date_start_real,"; + $sql .= " d.date_fin_validite as date_end,"; + $sql .= " d.date_cloture as date_end_real,"; $sql .= " d.fk_user_author,"; $sql .= " d.fk_user_ouverture,"; $sql .= " d.fk_user_cloture,"; $sql .= " d.fk_unit,"; - $sql .= " d.product_type as type"; + $sql .= " d.product_type as type,"; + $sql .= " d.rang"; $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid"; $sql .= " WHERE d.fk_contrat = ".((int) $this->id); if ($only_services == 1) { $sql .= " AND d.product_type = 1"; } - $sql .= " ORDER by d.rowid ASC"; + $sql .= " ORDER by d.rang ASC"; dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $result = $this->db->query($sql); @@ -855,19 +858,21 @@ class Contrat extends CommonObject $line->description = $objp->description; - $line->date_start = $this->db->jdate($objp->date_ouverture_prevue); - $line->date_start_real = $this->db->jdate($objp->date_ouverture); - $line->date_end = $this->db->jdate($objp->date_fin_validite); - $line->date_end_real = $this->db->jdate($objp->date_cloture); + $line->date_start = $this->db->jdate($objp->date_start); + $line->date_start_real = $this->db->jdate($objp->date_start_real); + $line->date_end = $this->db->jdate($objp->date_end); + $line->date_end_real = $this->db->jdate($objp->date_end_real); // For backward compatibility - $line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue); - $line->date_ouverture = $this->db->jdate($objp->date_ouverture); - $line->date_fin_validite = $this->db->jdate($objp->date_fin_validite); - $line->date_cloture = $this->db->jdate($objp->date_cloture); - $line->date_debut_prevue = $this->db->jdate($objp->date_ouverture_prevue); - $line->date_debut_reel = $this->db->jdate($objp->date_ouverture); - $line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite); - $line->date_fin_reel = $this->db->jdate($objp->date_cloture); + //$line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue); + //$line->date_ouverture = $this->db->jdate($objp->date_ouverture); + //$line->date_fin_validite = $this->db->jdate($objp->date_fin_validite); + //$line->date_cloture = $this->db->jdate($objp->date_cloture); + //$line->date_debut_prevue = $this->db->jdate($objp->date_ouverture_prevue); + //$line->date_debut_reel = $this->db->jdate($objp->date_ouverture); + //$line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite); + //$line->date_fin_reel = $this->db->jdate($objp->date_cloture); + + $line->rang = $objp->rang; // Retrieve all extrafields for contract line // fetch optionals attributes and labels @@ -892,10 +897,10 @@ class Contrat extends CommonObject if ($line->statut == ContratLigne::STATUS_INITIAL) { $this->nbofserviceswait++; } - if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) { + if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_end) || $line->date_end >= $now)) { $this->nbofservicesopened++; } - if ($line->statut == ContratLigne::STATUS_OPEN && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) { + if ($line->statut == ContratLigne::STATUS_OPEN && (!empty($line->date_end) && $line->date_end < $now)) { $this->nbofservicesexpired++; } if ($line->statut == ContratLigne::STATUS_CLOSED) { @@ -1492,6 +1497,9 @@ class Contrat extends CommonObject if (empty($remise_percent)) { $remise_percent = 0; } + if (empty($rang)) { + $rang = 0; + } if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); @@ -1555,6 +1563,7 @@ class Contrat extends CommonObject $sql .= ",date_fin_validite"; } $sql .= ", fk_unit"; + $sql .= ", rang"; $sql .= ") VALUES ("; $sql .= $this->id.", '', '".$this->db->escape($desc)."',"; $sql .= ($fk_product > 0 ? $fk_product : "null").","; @@ -1587,6 +1596,7 @@ class Contrat extends CommonObject $sql .= ",'".$this->db->idate($date_end)."'"; } $sql .= ", ".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); + $sql .= ", ".(!empty($rang) ? (int) $rang : "0"); $sql .= ")"; $resql = $this->db->query($sql); @@ -1644,17 +1654,18 @@ class Contrat extends CommonObject * @param float $tvatx Taux TVA * @param float $localtax1tx Local tax 1 rate * @param float $localtax2tx Local tax 2 rate - * @param int|string $date_debut_reel Date de debut reelle - * @param int|string $date_fin_reel Date de fin reelle + * @param int|string $date_start_real Date de debut reelle + * @param int|string $date_end_real Date de fin reelle * @param string $price_base_type HT or TTC * @param int $info_bits Bits of type of lines * @param int $fk_fournprice Fourn price id * @param int $pa_ht Buying price HT * @param array $array_options extrafields array * @param string $fk_unit Code of the unit to use. Null to use the default one + * @param string $rang Position * @return int < 0 si erreur, > 0 si ok */ - public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx = 0.0, $localtax2tx = 0.0, $date_debut_reel = '', $date_fin_reel = '', $price_base_type = 'HT', $info_bits = 0, $fk_fournprice = null, $pa_ht = 0, $array_options = 0, $fk_unit = null) + 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 = 0, $fk_unit = null, $rang = 0) { global $user, $conf, $langs, $mysoc; @@ -1672,6 +1683,9 @@ class Contrat extends CommonObject if (empty($fk_fournprice)) { $fk_fournprice = 0; } + if (empty($rang)) { + $rang = 0; + } $subprice = $price; $remise = 0; @@ -1688,7 +1702,7 @@ class Contrat extends CommonObject return -1; } - dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $date_debut_reel, $date_fin_reel, $tvatx, $localtax1tx, $localtax2tx, $price_base_type, $info_bits"); + dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $date_start_real, $date_end_real, $tvatx, $localtax1tx, $localtax2tx, $price_base_type, $info_bits, $rang"); $this->db->begin(); @@ -1760,17 +1774,18 @@ class Contrat extends CommonObject } else { $sql .= ",date_fin_validite = null"; } - if ($date_debut_reel > 0) { - $sql .= ",date_ouverture = '".$this->db->idate($date_debut_reel)."'"; + if ($date_start_real > 0) { + $sql .= ",date_ouverture = '".$this->db->idate($date_start_real)."'"; } else { $sql .= ",date_ouverture = null"; } - if ($date_fin_reel > 0) { - $sql .= ",date_cloture = '".$this->db->idate($date_fin_reel)."'"; + if ($date_end_real > 0) { + $sql .= ",date_cloture = '".$this->db->idate($date_end_real)."'"; } else { $sql .= ",date_cloture = null"; } $sql .= ", fk_unit = ".($fk_unit > 0 ? ((int) $fk_unit) : "null"); + $sql .= ", rang = ".(!empty($rang) ? ((int) $rang) : "0"); $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::updateline", LOG_DEBUG); @@ -2565,7 +2580,7 @@ class Contrat extends CommonObject if (!$error) { foreach ($this->lines as $line) { - $result = $clonedObj->addline($line->description, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_ouverture, $line->date_cloture, 'HT', 0, $line->info_bits, $line->fk_fournprice, $line->pa_ht, $line->array_options, $line->fk_unit); + $result = $clonedObj->addline($line->description, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_ouverture, $line->date_cloture, 'HT', 0, $line->info_bits, $line->fk_fournprice, $line->pa_ht, $line->array_options, $line->fk_unit, $line->rang); if ($result < 0) { $error++; $this->error = $clonedObj->error; @@ -2850,19 +2865,19 @@ class ContratLigne extends CommonObjectLine /** * @deprecated Use date_start */ - public $date_ouverture_prevue; // date start planned + //public $date_ouverture_prevue; // date start planned /** * @deprecated Use date_start_real */ - public $date_ouverture; // date start real + //public $date_ouverture; // date start real /** * @deprecated Use date_end */ - public $date_fin_validite; // date end planned + //public $date_fin_validite; // date end planned /** * @deprecated Use date_end_real */ - public $date_cloture; // date end real + //public $date_cloture; // date end real public $tva_tx; public $vat_src_code; @@ -2923,6 +2938,12 @@ class ContratLigne extends CommonObjectLine public $commentaire; + /** + * @var int line rank + */ + public $rang = 0; + + const STATUS_INITIAL = 0; const STATUS_OPEN = 4; const STATUS_CLOSED = 5; @@ -2952,7 +2973,8 @@ class ContratLigne extends CommonObjectLine //'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>125), 'fk_user_ouverture' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserStartingService', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>135), 'fk_user_cloture' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserClosingService', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>135), - 'statut' =>array('type'=>'smallint(6)', 'label'=>'Statut', 'enabled'=>1, 'visible'=>-1, 'position'=>500, 'arrayofkeyval'=>array(0=>'Draft', 4=>'Open', 5=>'Closed')) + 'statut' =>array('type'=>'smallint(6)', 'label'=>'Statut', 'enabled'=>1, 'visible'=>-1, 'position'=>500, 'arrayofkeyval'=>array(0=>'Draft', 4=>'Open', 5=>'Closed')), + 'rang' =>array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'position'=>500, 'default' =>0) ); // END MODULEBUILDER PROPERTIES @@ -2976,7 +2998,7 @@ class ContratLigne extends CommonObjectLine */ public function getLibStatut($mode) { - return $this->LibStatut($this->statut, $mode, ((!empty($this->date_fin_validite)) ? ($this->date_fin_validite < dol_now() ? 1 : 0) : -1)); + return $this->LibStatut($this->statut, $mode, ((!empty($this->date_end)) ? ($this->date_end < dol_now() ? 1 : 0) : -1)); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3091,10 +3113,10 @@ class ContratLigne extends CommonObjectLine $sql .= " p.fk_product_type as product_type,"; $sql .= " t.description,"; $sql .= " t.date_commande,"; - $sql .= " t.date_ouverture_prevue as date_ouverture_prevue,"; - $sql .= " t.date_ouverture as date_ouverture,"; - $sql .= " t.date_fin_validite as date_fin_validite,"; - $sql .= " t.date_cloture as date_cloture,"; + $sql .= " t.date_ouverture_prevue as date_start,"; + $sql .= " t.date_ouverture as date_start_real,"; + $sql .= " t.date_fin_validite as date_end,"; + $sql .= " t.date_cloture as date_end_real,"; $sql .= " t.tva_tx,"; $sql .= " t.vat_src_code,"; $sql .= " t.localtax1_tx,"; @@ -3119,7 +3141,8 @@ class ContratLigne extends CommonObjectLine $sql .= " t.fk_user_ouverture,"; $sql .= " t.fk_user_cloture,"; $sql .= " t.commentaire,"; - $sql .= " t.fk_unit"; + $sql .= " t.fk_unit,"; + $sql .= " t.rang"; $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as t LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = t.fk_product"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); @@ -3149,15 +3172,15 @@ class ContratLigne extends CommonObjectLine $this->description = $obj->description; $this->date_commande = $this->db->jdate($obj->date_commande); - $this->date_start = $this->db->jdate($obj->date_ouverture_prevue); - $this->date_start_real = $this->db->jdate($obj->date_ouverture); - $this->date_end = $this->db->jdate($obj->date_fin_validite); - $this->date_end_real = $this->db->jdate($obj->date_cloture); + $this->date_start = $this->db->jdate($obj->date_start); + $this->date_start_real = $this->db->jdate($obj->date_start_real); + $this->date_end = $this->db->jdate($obj->date_end); + $this->date_end_real = $this->db->jdate($obj->date_end_real); // For backward compatibility - $this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue); - $this->date_ouverture = $this->db->jdate($obj->date_ouverture); - $this->date_fin_validite = $this->db->jdate($obj->date_fin_validite); - $this->date_cloture = $this->db->jdate($obj->date_cloture); + //$this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue); + //$this->date_ouverture = $this->db->jdate($obj->date_ouverture); + //$this->date_fin_validite = $this->db->jdate($obj->date_fin_validite); + //$this->date_cloture = $this->db->jdate($obj->date_cloture); $this->tva_tx = $obj->tva_tx; $this->vat_src_code = $obj->vat_src_code; @@ -3186,6 +3209,8 @@ class ContratLigne extends CommonObjectLine $this->pa_ht = $marginInfos[0]; $this->fk_unit = $obj->fk_unit; + $this->rang = $obj->rang; + $this->fetch_optionals(); } @@ -3237,6 +3262,7 @@ class ContratLigne extends CommonObjectLine $this->fk_user_ouverture = (int) $this->fk_user_ouverture; $this->fk_user_cloture = (int) $this->fk_user_cloture; $this->commentaire = trim($this->commentaire); + $this->rang = (int) $this->rang; //if (empty($this->subprice)) $this->subprice = 0; if (empty($this->price_ht)) { $this->price_ht = 0; @@ -3261,16 +3287,16 @@ class ContratLigne extends CommonObjectLine } // For backward compatibility if (empty($this->date_start)) { - $this->date_start = $this->date_ouverture_prevue; + $this->date_start = $this->date_start; } if (empty($this->date_start_real)) { - $this->date_start = $this->date_ouverture; + $this->date_start_real = $this->date_start_real; } if (empty($this->date_end)) { - $this->date_start = $this->date_fin_validite; + $this->date_end = $this->date_end; } if (empty($this->date_end_real)) { - $this->date_start = $this->date_cloture; + $this->date_end_real = $this->date_end_real; } @@ -3318,10 +3344,10 @@ class ContratLigne extends CommonObjectLine $sql .= " label='".$this->db->escape($this->label)."',"; $sql .= " description='".$this->db->escape($this->description)."',"; $sql .= " date_commande=".($this->date_commande != '' ? "'".$this->db->idate($this->date_commande)."'" : "null").","; - $sql .= " date_ouverture_prevue=".($this->date_ouverture_prevue != '' ? "'".$this->db->idate($this->date_ouverture_prevue)."'" : "null").","; - $sql .= " date_ouverture=".($this->date_ouverture != '' ? "'".$this->db->idate($this->date_ouverture)."'" : "null").","; - $sql .= " date_fin_validite=".($this->date_fin_validite != '' ? "'".$this->db->idate($this->date_fin_validite)."'" : "null").","; - $sql .= " date_cloture=".($this->date_cloture != '' ? "'".$this->db->idate($this->date_cloture)."'" : "null").","; + $sql .= " date_ouverture_prevue=".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : "null").","; + $sql .= " date_ouverture=".($this->date_start_real != '' ? "'".$this->db->idate($this->date_start_real)."'" : "null").","; + $sql .= " date_fin_validite=".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : "null").","; + $sql .= " date_cloture=".($this->date_end_real != '' ? "'".$this->db->idate($this->date_end_real)."'" : "null").","; $sql .= " vat_src_code='".$this->db->escape($this->vat_src_code)."',"; $sql .= " tva_tx=".price2num($this->tva_tx).","; $sql .= " localtax1_tx=".price2num($this->localtax1_tx).","; @@ -3344,7 +3370,8 @@ class ContratLigne extends CommonObjectLine $sql .= " fk_user_ouverture=".($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture : "NULL").","; $sql .= " fk_user_cloture=".($this->fk_user_cloture > 0 ? $this->fk_user_cloture : "NULL").","; $sql .= " commentaire='".$this->db->escape($this->commentaire)."',"; - $sql .= " fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); + $sql .= " fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit).","; + $sql .= " rang=".(empty($this->rang) ? '0' : (int) $this->rang); $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -3365,9 +3392,9 @@ class ContratLigne extends CommonObjectLine if (!$error && !empty($conf->global->CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES)) { dol_syslog(get_class($this)."::update CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES is on so we update date for all lines", LOG_DEBUG); - if ($this->date_ouverture_prevue != $this->oldcopy->date_ouverture_prevue) { + if ($this->date_start != $this->oldcopy->date_start) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'contratdet SET'; - $sql .= " date_ouverture_prevue = ".($this->date_ouverture_prevue != '' ? "'".$this->db->idate($this->date_ouverture_prevue)."'" : "null"); + $sql .= " date_ouverture_prevue = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : "null"); $sql .= " WHERE fk_contrat = ".((int) $this->fk_contrat); $resql = $this->db->query($sql); @@ -3376,9 +3403,9 @@ class ContratLigne extends CommonObjectLine $this->error = "Error ".$this->db->lasterror(); } } - if ($this->date_fin_validite != $this->oldcopy->date_fin_validite) { + if ($this->date_end != $this->oldcopy->date_end) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'contratdet SET'; - $sql .= " date_fin_validite = ".($this->date_fin_validite != '' ? "'".$this->db->idate($this->date_fin_validite)."'" : "null"); + $sql .= " date_fin_validite = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : "null"); $sql .= " WHERE fk_contrat = ".((int) $this->fk_contrat); $resql = $this->db->query($sql); @@ -3463,11 +3490,12 @@ class ContratLigne extends CommonObjectLine $sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; $sql .= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; $sql .= " info_bits,"; + $sql .= " rang,"; $sql .= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; - if ($this->date_ouverture_prevue > 0) { + if ($this->date_start > 0) { $sql .= ",date_ouverture_prevue"; } - if ($this->date_fin_validite > 0) { + if ($this->date_end > 0) { $sql .= ",date_fin_validite"; } $sql .= ") VALUES ($this->fk_contrat, '', '".$this->db->escape($this->description)."',"; @@ -3482,6 +3510,7 @@ class ContratLigne extends CommonObjectLine $sql .= " ".price2num($this->remise_percent).",".price2num($this->subprice).","; $sql .= " ".price2num($this->total_ht).",".price2num($this->total_tva).",".price2num($this->total_localtax1).",".price2num($this->total_localtax2).",".price2num($this->total_ttc).","; $sql .= " '".$this->db->escape($this->info_bits)."',"; + $sql .= " ".(empty($this->rang) ? '0' : (int) $this->rang).","; $sql .= " ".price2num($this->price_ht).",".price2num($this->remise).","; if ($this->fk_fournprice > 0) { $sql .= ' '.((int) $this->fk_fournprice).','; @@ -3493,11 +3522,11 @@ class ContratLigne extends CommonObjectLine } else { $sql .= ' null'; } - if ($this->date_ouverture > 0) { - $sql .= ",'".$this->db->idate($this->date_ouverture)."'"; + if ($this->date_start > 0) { + $sql .= ",'".$this->db->idate($this->date_start)."'"; } - if ($this->date_cloture > 0) { - $sql .= ",'".$this->db->idate($this->date_cloture)."'"; + if ($this->date_end > 0) { + $sql .= ",'".$this->db->idate($this->date_end)."'"; } $sql .= ")"; @@ -3554,12 +3583,19 @@ class ContratLigne extends CommonObjectLine $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".ContratLigne::STATUS_OPEN.","; - $sql .= " date_ouverture = ".(dol_strlen($date) != 0 ? "'".$this->db->idate($date)."'" : "null").","; + $this->statut = ContratLigne::STATUS_OPEN; + $this->date_start = $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 = ".$this->statut.","; + $sql .= " date_ouverture = ".(dol_strlen($this->date_start_real) != 0 ? "'".$this->db->idate($this->date_start_real)."'" : "null").","; if ($date_end >= 0) { - $sql .= " date_fin_validite = ".(dol_strlen($date_end) != 0 ? "'".$this->db->idate($date_end)."'" : "null").","; + $sql .= " date_fin_validite = ".(dol_strlen($this->date_end) != 0 ? "'".$this->db->idate($this->date_end)."'" : "null").","; } - $sql .= " fk_user_ouverture = ".((int) $user->id).","; + $sql .= " fk_user_ouverture = ".((int) $this->fk_user_ouverture).","; $sql .= " date_cloture = null,"; $sql .= " commentaire = '".$this->db->escape($comment)."'"; $sql .= " WHERE rowid = ".((int) $this->id)." AND (statut = ".ContratLigne::STATUS_INITIAL." OR statut = ".ContratLigne::STATUS_CLOSED.")"; @@ -3575,13 +3611,6 @@ class ContratLigne extends CommonObjectLine // End call triggers if (!$error) { - $this->statut = ContratLigne::STATUS_OPEN; - $this->date_ouverture = $date; - $this->date_fin_validite = $date_end; - $this->fk_user_ouverture = $user->id; - $this->date_cloture = null; - $this->commentaire = $comment; - $this->db->commit(); return 1; } else { @@ -3600,18 +3629,18 @@ class ContratLigne extends CommonObjectLine * Close a contract line * * @param User $user Objet User who close contract - * @param int $date_end Date end + * @param int $date_end_real Date end * @param string $comment A comment typed by user * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers * @return int <0 if KO, >0 if OK */ - public function close_line($user, $date_end, $comment = '', $notrigger = 0) + public function close_line($user, $date_end_real, $comment = '', $notrigger = 0) { // phpcs:enable global $langs, $conf; // Update object - $this->date_cloture = $date_end; + $this->date_cloture = $date_end_real; $this->fk_user_cloture = $user->id; $this->commentaire = $comment; @@ -3622,7 +3651,7 @@ class ContratLigne extends CommonObjectLine $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".((int) ContratLigne::STATUS_CLOSED).","; - $sql .= " date_cloture = '".$this->db->idate($date_end)."',"; + $sql .= " date_cloture = '".$this->db->idate($date_end_real)."',"; $sql .= " fk_user_cloture = ".((int) $user->id).","; $sql .= " commentaire = '".$this->db->escape($comment)."'"; $sql .= " WHERE rowid = ".((int) $this->id)." AND statut = ".((int) ContratLigne::STATUS_OPEN); diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php index 3aa429ee89e..0254a7502f8 100644 --- a/htdocs/core/ajax/row.php +++ b/htdocs/core/ajax/row.php @@ -114,6 +114,8 @@ if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3) $perm = 1; } elseif ($table_element_line == 'projet_task' && $fk_element == 'fk_projet' && $user->rights->projet->creer) { $perm = 1; + } elseif ($table_element_line == 'contratdet' && $fk_element == 'fk_contrat' && $user->hasRight('contrat', 'creer')) { + $perm = 1; } else { $tmparray = explode('_', $table_element_line); $tmpmodule = $tmparray[0]; $tmpobject = preg_replace('/line$/', '', $tmparray[1]); @@ -152,7 +154,7 @@ if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3) // Reorder line to have position of children lines sharing same counter than parent lines // This should be useless because there is no need to have children sharing same counter than parent, but well, it's cleaner into database. - if (in_array($fk_element, array('fk_facture', 'fk_propal', 'fk_commande'))) { + if (in_array($fk_element, array('fk_facture', 'fk_propal', 'fk_commande','fk_contrat'))) { $result = $row->line_order(true); } } else { diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index c6cbab64965..57727e6f92f 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -483,6 +483,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ migrate_user_photospath(); migrate_user_photospath2(); } + + // Scripts for 17.0 + $afterversionarray = explode('.', '16.0.9'); + $beforeversionarray = explode('.', '17.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { + migrate_contractdet_rank(); + } } @@ -5137,3 +5144,62 @@ function migrate_export_import_profiles($mode = 'export') print '\n"; } } + +/** + * Migrate Rank into contract line + * + * @return void + */ +function migrate_contractdet_rank() +{ + + global $db, $langs; + + $error = 0; + $resultstring = ''; + + $db->begin(); + print '\n"; + $resqlUpd = $db->query($sqlUpd); + if (!$resqlUpd) { + dol_print_error($db); + $error++; + } + + $current_contract = $obj->cid; + } + } else { + $error++; + } + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } + + print ''.$langs->trans('MigrationContractLineRank')."
\n"; + print ''; + + if ($resultstring) { + print $resultstring; + } else { + print '\n"; + } +} diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index ad8217153be..d0c841fe802 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -214,3 +214,4 @@ Loaded=Loaded FunctionTest=Function test NodoUpgradeAfterDB=No action requested by external modules after upgrade of database NodoUpgradeAfterFiles=No action requested by external modules after upgrade of files or directories +MigrationContractLineRank=Migrate Contract Line to use Rank (and enable Reorder) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index b30391becc7..97c4e9ba646 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -450,7 +450,7 @@ class MyObject extends CommonObject $sql = "SELECT "; $sql .= $this->getFieldList('t'); - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { $sql .= " WHERE t.entity IN (".getEntity($this->element).")"; } else { diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 16a471ac51d..5ea1313a16a 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -126,11 +126,11 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ // Set $enablepermissioncheck to 1 to enable a minimum low level of checks $enablepermissioncheck = 0; if ($enablepermissioncheck) { - $permissiontoread = $user->rights->mymodule->myobject->read; - $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php - $permissiontodelete = $user->rights->mymodule->myobject->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); - $permissionnote = $user->rights->mymodule->myobject->write; // Used by the include of actions_setnotes.inc.php - $permissiondellink = $user->rights->mymodule->myobject->write; // Used by the include of actions_dellink.inc.php + $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read'); + $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php + $permissiontodelete = $user->hasRight('mymodule', 'myobject', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); + $permissionnote = $user->hasRight('mymodule', 'myobject', 'write'); // Used by the include of actions_setnotes.inc.php + $permissiondellink = $user->hasRight('mymodule', 'myobject', 'write'); // Used by the include of actions_dellink.inc.php } else { $permissiontoread = 1; $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php From ac4f0d9927591e287800cc8a0ba8a03474ea074f Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 7 Oct 2022 14:56:08 +0200 Subject: [PATCH 03/13] chore: reset debug --- htdocs/contrat/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 9a81c1ccac4..99eb5a4550a 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1494,7 +1494,7 @@ if ($action == 'create') { print '
'; while ($cursorline <= $nbofservices) { - print '
'; + print '
'; print ''; print ''; print ''; @@ -1503,7 +1503,7 @@ if ($action == 'create') { // Area with common detail of line print '
'; - print '
'.$langs->trans("NothingToDo")."
'; + + $sql = 'SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM '.$db->prefix().'contratdet as cd INNER JOIN '.$db->prefix().'contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0'; + $sql .=' ORDER BY c.rowid,cd.rowid'; + + $resql = $db->query($sql); + if ($resql) { + $currentRank=0; + $current_contract=0; + while ($obj = $db->fetch_object($resql)) { + if (empty($current_contract) || $current_contract==$obj->cid) { + $currentRank++; + } else { + $currentRank=1; + } + + $sqlUpd = 'UPDATE '.$db->prefix().'contratdet SET rang='.(int) $currentRank.' WHERE rowid='.(int) $obj->cdid; + $resultstring .= '
'.$sqlUpd."
'.$langs->trans("NothingToDo")."
'; + print '
'; $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,"; $sql .= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,"; From 9424a7a92be09629721d72193aa02451a4fe3390 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 7 Oct 2022 14:59:49 +0200 Subject: [PATCH 04/13] remove debug --- htdocs/contrat/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 99eb5a4550a..068feb1645d 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1554,7 +1554,7 @@ if ($action == 'create') { } print ''; } else { - print ''; + print ''; } print "\n"; From 28b69f5cd9ede6f677b92d8b2616a3b5bbedb549 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 9 Oct 2022 14:15:43 +0200 Subject: [PATCH 05/13] chore: travis --- htdocs/install/upgrade2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 57727e6f92f..463c2b2df4c 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -5161,8 +5161,8 @@ function migrate_contractdet_rank() $db->begin(); print '\n"; $resqlUpd = $db->query($sqlUpd); if (!$resqlUpd) { From b6452bd2c7398b832bcc0691f641126d1aa9a78e Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 9 Oct 2022 14:52:15 +0200 Subject: [PATCH 06/13] fix travis (website template) --- .../website_template-stellar/containers/page23.tpl.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/doctemplates/websites/website_template-stellar/containers/page23.tpl.php b/htdocs/install/doctemplates/websites/website_template-stellar/containers/page23.tpl.php index 37ea0bf165d..43664b7984b 100644 --- a/htdocs/install/doctemplates/websites/website_template-stellar/containers/page23.tpl.php +++ b/htdocs/install/doctemplates/websites/website_template-stellar/containers/page23.tpl.php @@ -39,7 +39,7 @@ ob_start(); @@ -101,7 +101,7 @@ ob_start();

Ipsum consequat

-

Donec imperdiet consequat consequat. Suspendisse feugiat congue
+

Donec imperdiet consequat consequat. Suspendisse feugiat congue
posuere. Nulla massa urna, fermentum eget quam aliquet.

    @@ -138,7 +138,7 @@ ob_start();

    Congue imperdiet

    -

    Donec imperdiet consequat consequat. Suspendisse feugiat congue
    +

    Donec imperdiet consequat consequat. Suspendisse feugiat congue
    posuere. Nulla massa urna, fermentum eget quam aliquet.

    From 460ecddaca67ea978a9db76477046bcea3a85a56 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Mon, 10 Oct 2022 10:49:19 +0200 Subject: [PATCH 07/13] update code towards php8 compliance --- htdocs/core/modules/commande/doc/pdf_einstein.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 50071b029e0..e0dff278f96 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -871,7 +871,7 @@ class pdf_einstein extends ModelePDFCommandes // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if ($object->fk_bank > 0) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank From 1d7b6a084dbd8e20a48563cd9cae0dcd9a282363 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Mon, 10 Oct 2022 11:00:54 +0200 Subject: [PATCH 08/13] update code towards php8 compliance --- .../core/modules/commande/doc/pdf_eratosthene.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 6 +++--- htdocs/core/modules/facture/doc/pdf_sponge.modules.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index d1683f91ee7..131e159196b 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -1088,7 +1088,7 @@ class pdf_eratosthene extends ModelePDFCommandes // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if ($object->fk_bank > 0) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 4ce7b3b3aa5..3d7da995e6f 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1134,10 +1134,10 @@ class pdf_crabe extends ModelePDFFactures // Check a payment mode is defined if (empty($object->mode_reglement_code) && empty($conf->global->FACTURE_CHQ_NUMBER) - && empty($conf->global->FACTURE_RIB_NUMBER)) { + && !getDolGlobalInt('FACTURE_RIB_NUMBER')) { $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"); } elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)) - || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) { + || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) { // Avoid having any valid PDF with setup that is not complete $outputlangs->load("errors"); @@ -1247,7 +1247,7 @@ class pdf_crabe extends ModelePDFFactures // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if ($object->fk_bank > 0) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index e8269039aa8..da278cb45ac 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -1242,10 +1242,10 @@ class pdf_sponge extends ModelePDFFactures // Check a payment mode is defined if (empty($object->mode_reglement_code) && empty($conf->global->FACTURE_CHQ_NUMBER) - && empty($conf->global->FACTURE_RIB_NUMBER)) { + && !getDolGlobalInt('FACTURE_RIB_NUMBER')) { $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"); } elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)) - || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) { + || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) { // Avoid having any valid PDF with setup that is not complete $outputlangs->load("errors"); @@ -1358,7 +1358,7 @@ class pdf_sponge extends ModelePDFFactures // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if ($object->fk_bank > 0) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank From 731ff10bedd4ceeec6fc76397db4cf0665e3b964 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Mon, 10 Oct 2022 11:03:54 +0200 Subject: [PATCH 09/13] update code towards php8 compliance --- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 2 +- htdocs/core/modules/propale/doc/pdf_cyan.modules.php | 2 +- .../modules/stocktransfer/doc/pdf_eagle_proforma.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 3d507f816dc..231d8c1ddff 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -1053,7 +1053,7 @@ class pdf_azur extends ModelePDFPropales // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if (!empty($object->fk_account) || !empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if (!empty($object->fk_bank)) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 0da947cdd95..9bffe9009fb 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -1172,7 +1172,7 @@ class pdf_cyan extends ModelePDFPropales // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if ($object->fk_bank > 0) { $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank diff --git a/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php b/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php index 381710e2697..ef73d526ed6 100644 --- a/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php +++ b/htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php @@ -978,7 +978,7 @@ class pdf_eagle_proforma extends ModelePDFCommandes // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if (!empty($object->fk_account) || !empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if (!empty($object->fk_account) || !empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = (empty($object->fk_account) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); if (!empty($object->fk_bank)) $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank $account = new Account($this->db); From 5a1716f62569b5fdedbb7d222def655d0bcf2099 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Mon, 10 Oct 2022 11:05:09 +0200 Subject: [PATCH 10/13] update code towards php8 compliance --- .../core/modules/supplier_proposal/doc/pdf_aurore.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index 5ed82f597fb..fe439ea0790 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -872,7 +872,7 @@ class pdf_aurore extends ModelePDFSupplierProposal // If payment mode not forced or forced to VIR, show payment with BAN if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { - if (!empty($object->fk_bank) || !empty($conf->global->FACTURE_RIB_NUMBER)) { + if (!empty($object->fk_bank) || getDolGlobalInt('FACTURE_RIB_NUMBER')) { $bankid = (empty($object->fk_bank) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_bank); $account = new Account($this->db); $account->fetch($bankid); From fea1b2ef14a333704bae12c415fc9d51ff0457b7 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 10 Oct 2022 15:00:51 +0200 Subject: [PATCH 11/13] review --- htdocs/compta/facture/class/facture.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 32798f3724d..42be01bcc13 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5526,7 +5526,7 @@ class Facture extends CommonInvoice $sendContent = make_substitutions($content, $substitutionarray, $outputlangs, 1); // Recipient - $to = ''; + $to = array(); $res = $tmpinvoice->fetch_thirdparty(); $recipient = $tmpinvoice->thirdparty; if ($res > 0) { @@ -5534,13 +5534,12 @@ class Facture extends CommonInvoice if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { foreach ($tmparraycontact as $data_email) { if (!empty($data_email['email'])) { - $to = $data_email['email']; - break; + $to[] = $data_email['firstname'] . ' '. $data_email['lastname']. '<'.$data_email['email'].'>'; } } } if (empty($to) && !empty($recipient->email)) { - $to = $recipient->email; + $to[] = $recipient->email; } else { $errormesg = "Failed to send remind to thirdparty id=".$tmpinvoice->socid.". No email defined for user."; $error++; @@ -5557,9 +5556,11 @@ class Facture extends CommonInvoice $error++; } - if (!$error && $to) { + if (!$error && !empty($to)) { $this->db->begin(); + $to = implode(',', $to); + // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; From 26a1825411f0c0a81b1bb7b13f211587679d66c5 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 10 Oct 2022 15:54:03 +0200 Subject: [PATCH 12/13] review --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 42be01bcc13..69bfb73e867 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5534,7 +5534,7 @@ class Facture extends CommonInvoice if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { foreach ($tmparraycontact as $data_email) { if (!empty($data_email['email'])) { - $to[] = $data_email['firstname'] . ' '. $data_email['lastname']. '<'.$data_email['email'].'>'; + $to[] = $tmpinvoice->thirdparty->contact_get_property($data_email['id'], 'email'); } } } From 21145a1d59d536f5dcd14315c49d52a0650c43ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 13 Oct 2022 09:41:49 +0200 Subject: [PATCH 13/13] fix warnings --- .../product/stock/stocktransfer/class/stocktransfer.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index a71098fc2bf..5ffb56ced44 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2021 Gauthier VERDOL - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) 2022 Frédéric France * * 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 @@ -229,7 +229,7 @@ class StockTransfer extends CommonObject // Translate some data of arrayofkeyval if (is_object($langs)) { foreach ($this->fields as $key => $val) { - if (is_array($val['arrayofkeyval'])) { + if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { foreach ($val['arrayofkeyval'] as $key2 => $val2) { $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); }
 sss 
'; - $sql = 'SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM '.$db->prefix().'contratdet as cd INNER JOIN '.$db->prefix().'contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0'; - $sql .=' ORDER BY c.rowid,cd.rowid'; + $sql = "SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM ".$db->prefix()."contratdet as cd INNER JOIN ".$db->prefix()."contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0"; + $sql .=" ORDER BY c.rowid,cd.rowid"; $resql = $db->query($sql); if ($resql) { @@ -5175,7 +5175,7 @@ function migrate_contractdet_rank() $currentRank=1; } - $sqlUpd = 'UPDATE '.$db->prefix().'contratdet SET rang='.(int) $currentRank.' WHERE rowid='.(int) $obj->cdid; + $sqlUpd = "UPDATE ".$db->prefix()."contratdet SET rang=".(int) $currentRank." WHERE rowid=".(int) $obj->cdid; $resultstring .= '
'.$sqlUpd."