Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
ldestailleur
2025-05-12 20:14:44 +02:00
9 changed files with 86 additions and 30 deletions

View File

@@ -1924,6 +1924,7 @@ if (empty($reshook)) {
$res = $product->fetch($productid);
$type = $product->type;
$$price_base_type = $product->price_base_type;
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
$price_min = $product->price_min;

View File

@@ -59,7 +59,7 @@ include '../../main.inc.php';
$objectType = GETPOST('objectType', 'aZ09');
$objectId = GETPOST('objectId', 'aZ09');
$field = GETPOST('field', 'aZ09');
$value = GETPOST('value', 'aZ09');
$value = GETPOST('value', 'alpha');
$module = getElementProperties($objectType)['module'];
$element_ref = '';

View File

@@ -3754,7 +3754,7 @@ class Form
print($hidelabel ? '' : $langs->trans("RefOrLabel") . ' : ') . '<input type="text" class="'.$morecss.'" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . ($placeholder ? ' placeholder="' . $placeholder . '"' : '') . '>';
} else {
print $this->select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre, '', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
print $this->select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre, '', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, getDolGlobalInt('SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'), $placeholder);
}
}

View File

@@ -411,7 +411,7 @@ class FormAI extends Form
console.log('Add response into field \'#'+htmlname+'\': '+response);
jQuery('#'+htmlname).val(response); // If #htmlcontent is a input name or textarea
jQuery('#'+htmlname).html(response); // If #htmlContent is a div
jQuery('#'+htmlname).html(response).trigger('change'); // If #htmlContent is a div and trigger event change for extrafield update
//jQuery('#'+htmlname+'preview').val(response);
if (CKEDITOR.instances) {

View File

@@ -229,23 +229,38 @@ if (empty($reshook) && !empty($object->table_element) && isset($extrafields->att
$fieldid = 'socid';
}
print '<td class="right"><a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$valueid.'&action=edit_extras&token='.newToken().'&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a></td>';
}
if (isModEnabled("ai") && $action == 'edit_extras' && GETPOST('attribute') == $tmpkeyextra && !empty($extrafields->attributes[$object->table_element]["aiprompt"][$tmpkeyextra])) {
$showlinktoai = "extrafieldfiller";
$showlinktoailabel = $langs->trans("FillExtrafieldWithAi");
$htmlname = "options_".$tmpkeyextra;
$onlyenhancements = "textgenerationextrafield";
$morecss = "editfielda";
$aiprompt = $extrafields->attributes[$object->table_element]["aiprompt"][$tmpkeyextra];
$out = "";
// Fill $out
include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
print '<td class="right">';
print '<!-- TODO Step 3 Then a next step will be to use the ajax call core/aja/updateextrafield.php to update field in database directly with no need to pass by edit_extras step -->';
print $out;
print '</td>';
if (isModEnabled("ai") && !empty($extrafields->attributes[$object->table_element]["aiprompt"][$tmpkeyextra])) {
$showlinktoai = "extrafieldfiller_".$tmpkeyextra;
$showlinktoailabel = $langs->trans("FillExtrafieldWithAi");
$htmlname = !empty($object->id) ? $object->element.'_extras_'.$tmpkeyextra.'_'.$object->id : "options_".$tmpkeyextra;
$onlyenhancements = "textgenerationextrafield";
$morecss = "editfielda";
$aiprompt = $extrafields->attributes[$object->table_element]["aiprompt"][$tmpkeyextra];
$out = "";
// Fill $out
include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
print $out;
print '<script>
$(document).ready(function() {
$("#'.$htmlname.'").on("change", function () {
value = $(this).html();
$.ajax({
method: "POST",
dataType: "json",
url: "'. DOL_URL_ROOT.'/core/ajax/updateextrafield.php",
data: {"token": "'.currentToken().'", "objectType": "'.$object->element.'", "objectId": "'.$object->id.'", "field": "'.$tmpkeyextra.'", "value": value},
success: function(response) {
console.log("Extrafield "+'.$tmpkeyextra.'+" successfully updated");
},
});
});
});
</script>';
}
print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$valueid.'&action=edit_extras&token='.newToken().'&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a>';
print'</td>';
}
print '</tr></table>';
print '</td>';

View File

@@ -41,15 +41,10 @@ if (empty($conf) || !is_object($conf)) {
exit(1);
}
if (empty($langs)) {
print 'Parameter langs not defined.';
exit(1);
}
if (empty($object)) {
print 'Parameter object not defined.';
exit(1);
}
if (empty($htmlname)) {
print 'Parameter htmlname not defined.';
exit(1);
@@ -163,7 +158,7 @@ if ($showlinktoai) {
if (empty($onlyenhancements)) {
$onlyenhancements = '';
}
if (!empty($aiprompt)) {
if (!empty($aiprompt) && !empty($object)) {
$formai->setSubstitFromObject($object, $langs);
$aiprompt = make_substitutions($aiprompt, $formai->substit);
}

View File

@@ -131,13 +131,14 @@ class Interventions extends DolibarrApi
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of property names
* @param string $contact_type {@choice '',thirdparty,internal,external} Type of contacts
* @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0*
* @return array Array of order objects
* @phan-return array<object>
* @phpstan-return array<object>
*
* @throws RestException
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $contact_type = '')
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $contact_type = '', $pagination_data = false)
{
if (!DolibarrApiAccess::$user->hasRight('ficheinter', 'lire')) {
throw new RestException(403);
@@ -177,6 +178,9 @@ class Interventions extends DolibarrApi
}
}
//this query will return total interventions with the filters given
$sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
@@ -209,6 +213,23 @@ class Interventions extends DolibarrApi
throw new RestException(503, 'Error when retrieve intervention list : '.$this->db->lasterror());
}
//if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
if ($pagination_data) {
$totalsResult = $this->db->query($sqlTotals);
$total = $this->db->fetch_object($totalsResult)->total;
$tmp = $obj_ret;
$obj_ret = [];
$obj_ret['data'] = $tmp;
$obj_ret['pagination'] = [
'total' => (int) $total,
'page' => $page, //count starts from 0
'page_count' => ceil((int) $total / $limit),
'limit' => $limit
];
}
return $obj_ret;
}

View File

@@ -335,7 +335,7 @@ if ($action == 'fetch' && !empty($id)) {
if (empty($mode) || $mode == 1) { // mode=1: customer
$arrayresult = $form->select_produits_list(0, $htmlname, $type, getDolGlobalInt('PRODUIT_LIMIT_SIZE', 1000), $price_level, $searchkey, $status, $finished, $outjson, $socid, '1', 0, '', $hidepriceinlabel, $warehouseStatus, $status_purchase, $warehouseId);
} elseif ($mode == 2) { // mode=2: supplier
$arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, getDolGlobalInt('PRODUIT_LIMIT_SIZE', 1000), $alsoproductwithnosupplierprice);
$arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, getDolGlobalInt('PRODUIT_LIMIT_SIZE', 1000), $alsoproductwithnosupplierprice, '', getDolGlobalInt('SUPPLIER_SHOW_STOCK_IN_PRODUCTS_COMBO'));
}
$db->close();

View File

@@ -385,12 +385,13 @@ if ($type_element == 'contract') { // Order
$thirdTypeSelect = 'customer';
}
$parameters = array();
$totalnboflines = 0;
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
if (!empty($sql_select)) {
$sql = $sql_select;
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= ' d.description as description,';
if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
$sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
@@ -418,6 +419,9 @@ if (!empty($sql_select)) {
if ($type_element != 'fichinter') {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= $where;
$sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
if ($sref) {
@@ -434,6 +438,15 @@ if (!empty($sql_select)) {
}
$sql .= ")";
}
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= $db->order($sortfield, $sortorder);
$resql = $db->query($sql);
@@ -518,6 +531,9 @@ if ($sql_select) {
print '</th>';
print '<th class="liste_titre center">';
print '</th>';
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '<th class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
print $searchpicto;
@@ -537,6 +553,9 @@ if ($sql_select) {
print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
$parameters = array('param'=>$param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print "</tr>\n";
$i = 0;
@@ -740,7 +759,9 @@ if ($sql_select) {
$total_ht += (float) $objp->total_ht;
print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
$parameters = array('obj' => $objp);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print "</tr>\n";
$i++;
}
@@ -755,6 +776,9 @@ if ($sql_select) {
print '<td class="right">'.$total_qty.'</td>';
print '<td class="right">'.price($total_ht).'</td>';
print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print "</table>";
print '</div>';