diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index dcfdbd16518..832b5b5e539 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -623,7 +623,7 @@ class AccountancyCategory // extends CommonObject /** * Function to set the property ->sdc (and ->sdcperaccount) that is the result of an accounting account from the ledger with a direction and a period * - * @param int|array $cpt Accounting account or array of accounting account + * @param string|int|array $cpt Accounting account or array of accounting account * @param int $date_start Date start * @param int $date_end Date end * @param int<0,1> $sens Sens of the account: 0: credit - debit (use this by default), 1: debit - credit diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index f792dd57a99..d2ec4ed69a4 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -1084,11 +1084,11 @@ if ($object->fetch($id) >= 0) { // Standard Extrafield feature if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED')) { $contactstatic = new Contact($db); - $elementype = $contactstatic->table_element; + $elementtype = $contactstatic->table_element; // fetch optionals attributes and labels dol_include_once('/core/class/extrafields.class.php'); $extrafields = new ExtraFields($db); - $extrafields->fetch_name_optionals_label($elementype); + $extrafields->fetch_name_optionals_label($elementtype); if (!empty($extrafields->attributes[$elementtype]['type'])) { foreach ($extrafields->attributes[$elementtype]['type'] as $key => &$value) { if ($value == 'radio') { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 7c2d694897d..f1eecad6a1c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2263,6 +2263,12 @@ if (empty($reshook)) { $object->situation_counter += 1; + // Set extrafields from the create form BEFORE createFromCurrent(), so they are already + // present when create() inserts them and fires the BILL_CREATE trigger. This avoids firing + // BILL_CREATE a second time just to expose the extrafields (#32217). + $extrafields->fetch_name_optionals_label($object->table_element); + $extrafields->setOptionalsFromPost(null, $object); + $id = $object->createFromCurrent($user); if ($id <= 0) { $mesg = $object->error; @@ -2270,13 +2276,6 @@ if (empty($reshook)) { $nextSituationInvoice = new Facture($db); $nextSituationInvoice->fetch($id); - // create extrafields with data from create form - $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element); - $ret = $extrafields->setOptionalsFromPost(null, $nextSituationInvoice); - if ($ret > 0) { - $nextSituationInvoice->insertExtraFields(); - } - // Hooks $parameters = array('origin_type' => $object->origin_type, 'origin_id' => $object->origin_id); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $nextSituationInvoice, $action); // Note that $action and $object may have been diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7898437bb39..79242f5e608 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1184,7 +1184,10 @@ class Facture extends CommonInvoice // Retrieve all extrafield // fetch optionals attributes and labels - $this->fetch_optionals(); + // (unless the caller already set array_options, e.g. from a create form, so we don't overwrite them) + if (empty($this->array_options)) { + $this->fetch_optionals(); + } if (!empty($this->array_options)) { $facture->array_options = $this->array_options; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index eefbc6bbcbd..c6b9fcac235 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -386,7 +386,7 @@ if ($modecompta == 'BOOKKEEPING') { $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere); foreach ($cpts as $j => $cpt) { - $return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc'])); + $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc'])); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultN = 0; diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 09328db8ca3..57209912ec3 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -560,7 +560,7 @@ if ($modecompta == 'CREANCES-DETTES') { ) { //var_dump($monthtoprocess.'_'.$yeartoprocess); if (isset($cpt['account_number'])) { - $return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess); + $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultM = 0; diff --git a/htdocs/contrat/class/contratligne.class.php b/htdocs/contrat/class/contratligne.class.php index 07e4ef30701..56e081918ab 100644 --- a/htdocs/contrat/class/contratligne.class.php +++ b/htdocs/contrat/class/contratligne.class.php @@ -526,8 +526,8 @@ class ContratLigne extends CommonObjectLine $this->ref = $obj->rowid; $this->tms = $this->db->jdate($obj->tms); - $this->fk_contrat = $obj->fk_contrat; - $this->fk_product = $obj->fk_product; + $this->fk_contrat = (int) $obj->fk_contrat; + $this->fk_product = (int) $obj->fk_product; $this->statut = $obj->statut; $this->product_ref = $obj->product_ref; $this->product_label = $obj->product_label; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5f829ab5565..09299384eb4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10320,7 +10320,7 @@ abstract class CommonObject public function isInt($info) { if (is_array($info)) { - if (isset($info['type']) && (preg_match('/(^int|int$)/i', $info['type']))) { + if (isset($info['type']) && (preg_match('/^(?:tiny|small|medium|big)?int|int$/i', $info['type']))) { return true; } else { return false; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index e7e58348a92..cd4ad6885aa 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3144,12 +3144,12 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed = 1; } $original_file = $conf->order->multidir_output[$entity].'/'.$original_file; - } elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) { + } elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) { // Wrapping pour les apercu intervention if ($fuser->hasRight('ficheinter', $lire)) { $accessallowed = 1; } - $original_file = $conf->ficheinter->dir_output.'/'.$original_file; + $original_file = $conf->ficheinter->multidir_output[$entity].'/'.$original_file; } elseif (($modulepart == 'apercucontract') && !empty($conf->contract->multidir_output[$entity])) { // Wrapping pour les apercu contrat if ($fuser->hasRight('contrat', $lire)) { @@ -3421,13 +3421,13 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed = 1; } $original_file = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; - } elseif (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output)) { + } elseif (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) { // Wrapping for interventions if ($fuser->hasRight('ficheinter', $lire) || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } - $original_file = $conf->ficheinter->dir_output.'/'.$original_file; - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; + $original_file = $conf->ficheinter->multidir_output[$entity].'/'.$original_file; + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".((int) $entity); } elseif ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output)) { // Wrapping pour les deplacements et notes de frais if ($fuser->hasRight('deplacement', $lire) || preg_match('/^specimen/i', $original_file)) { diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 84c28e54826..426b11cab90 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1232,7 +1232,7 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR dbt.".$dbt_keyfield." IS NULL OR dbt.".$dbt_keyfield." = 0)"; } - } elseif (isModEnabled('multicompany')) { + } elseif (isModEnabled('multicompany') && (!empty($object->ismultientitymanaged) || !isset($object->ismultientitymanaged))) { // If multicompany, and user is an internal user with all permissions, check that object is in correct entity $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb"; $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt"; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 81143f6a252..37a8c345fd5 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -2311,31 +2311,37 @@ if ($action == 'create' && $usercancreate) { print ''; print ''; if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) { - if (isset($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) { - $deliverableQty = min($quantityToBeDelivered, $stock - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]); - } else { - if (!isset($alreadyQtySetted[$line->fk_product])) { - $alreadyQtySetted[$line->fk_product] = array(); + // For a virtual product (kit), $deliverableQty is already min($quantityToBeDelivered, $stock) computed above + // and the per-warehouse "stock" returned by loadStockForVirtualProduct() is $qtyWish, not a shared physical + // stock. The cross-line $alreadyQtySetted cap must not be applied for kits, otherwise the 2nd and next order + // lines of the same kit would be wrongly pre-filled with 0. + $tooltipClass = $tooltipTitle = ''; + if ($productChildrenNb <= 0) { + if (isset($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) { + $deliverableQty = min($quantityToBeDelivered, $stock - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]); + } else { + if (!isset($alreadyQtySetted[$line->fk_product])) { + $alreadyQtySetted[$line->fk_product] = array(); + } + + $deliverableQty = min($quantityToBeDelivered, $stock); } - $deliverableQty = min($quantityToBeDelivered, $stock); + if ($deliverableQty < 0) { + $deliverableQty = 0; + } + + if (!empty($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) { + $tooltipClass = ' classfortooltip'; + $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtySetted[$line->fk_product][intval($warehouse_id)]; + } else { + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = 0; + } + + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = $deliverableQty + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]; } - if ($deliverableQty < 0) { - $deliverableQty = 0; - } - - $tooltipClass = $tooltipTitle = ''; - if (!empty($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) { - $tooltipClass = ' classfortooltip'; - $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines') . ' : ' . $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]; - } else { - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = 0; - } - - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = $deliverableQty + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]; - - $inputName = 'qtyl' . $indiceAsked . '_' . $subj; + $inputName = 'qtyl'.$indiceAsked.'_'.$subj; if (GETPOSTISSET($inputName)) { $deliverableQty = GETPOSTINT($inputName); } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 94090b64826..4da322b8b69 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -535,7 +535,12 @@ class Expedition extends CommonObject // virtual products $line = $this->lines[$i]; if ($line->fk_product > 0) { - if (!isset($kits_list[$line->fk_product])) { + // We group kit lines by the fulfilled order line (fk_elementdet) and not by product id: when a same kit product + // is present on several distinct order lines, each order line must keep its own shipment line so the ordered + // qty stays consistent with the shipped qty (grouping by product would sum the shipped qty of all lines while + // keeping the ordered qty of a single line, resulting in a wrong/negative remaining qty to ship). Several + // warehouse pickings of the same order line still share the same fk_elementdet and are grouped together. + if (!isset($kits_list[$line->fk_elementdet])) { if (!is_object($line->product)) { $line_product = new Product($this->db); $result = $line_product->fetch($line->fk_product, '', '', '', 1, 1, 1); @@ -550,13 +555,13 @@ class Expedition extends CommonObject $line_product->get_sousproduits_arbo(); $prods_arbo = $line_product->get_arbo_each_prod($line->qty); if (count($prods_arbo) > 0) { - $kits_list[$line->fk_product] = array( + $kits_list[$line->fk_elementdet] = array( 'arbo' => $prods_arbo, 'total_qty' => $line->qty, ); } } else { - $kits_list[$line->fk_product]['total_qty'] += $line->qty; + $kits_list[$line->fk_elementdet]['total_qty'] += $line->qty; } } } @@ -564,20 +569,21 @@ class Expedition extends CommonObject } $kits_id_cached = array(); $sub_kits_id_cached = array(); + $sub_parents_cached = array(); for ($i = 0; $i < $num; $i++) { $line = $this->lines[$i]; if (empty($line->product_type) || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) { $line_id = 0; - if (!isset($kits_id_cached[$line->fk_product])) { - if (!isset($line->detail_batch) || (isset($kits_list[$line->fk_product]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE'))) { // no batch management or is kit - $qty = isset($kits_list[$line->fk_product]) ? $kits_list[$line->fk_product]['total_qty'] : $line->qty; - $warehouse_id = (isset($kits_list[$line->fk_product]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) ? 0 : $line->entrepot_id; + if (!isset($kits_id_cached[$line->fk_elementdet])) { + if (!isset($line->detail_batch) || (isset($kits_list[$line->fk_elementdet]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE'))) { // no batch management or is kit + $qty = isset($kits_list[$line->fk_elementdet]) ? $kits_list[$line->fk_elementdet]['total_qty'] : $line->qty; + $warehouse_id = (isset($kits_list[$line->fk_elementdet]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) ? 0 : $line->entrepot_id; $line_id = $this->create_line($warehouse_id, $line->origin_line_id, $qty, $line->rang, $line->array_options, 0, $line->fk_product); if ($line_id <= 0) { $error++; } - if (isset($kits_list[$line->fk_product])) { - $kits_id_cached[$line->fk_product] = $line_id; + if (isset($kits_list[$line->fk_elementdet])) { + $kits_id_cached[$line->fk_elementdet] = $line_id; } } else { // with batch management if ($this->create_line_batch($line, $line->array_options) <= 0) { @@ -585,13 +591,12 @@ class Expedition extends CommonObject } } } else { - $line_id = $kits_id_cached[$line->fk_product]; + $line_id = $kits_id_cached[$line->fk_elementdet]; } // virtual products - if (isset($kits_list[$line->fk_product]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) { - $prods_arbo = $kits_list[$line->fk_product]['arbo']; - $total_qty = $kits_list[$line->fk_product]['total_qty']; + if (isset($kits_list[$line->fk_elementdet]) && !getDolGlobalInt('PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) { + $prods_arbo = $kits_list[$line->fk_elementdet]['arbo']; // get all children of virtual product $parent_line_id = $line_id; // parent line created @@ -619,10 +624,10 @@ class Expedition extends CommonObject if ($product_child_level != $level_last) { $parent_line_id = $line_id; // last line id $parent_product_id = $product_child_id; // last line id - if (isset($kits_id_cached[$parent_product_id])) { - $parent_line_id = $kits_id_cached[$parent_product_id]; + if (isset($sub_parents_cached[$line->fk_elementdet][$parent_product_id])) { + $parent_line_id = $sub_parents_cached[$line->fk_elementdet][$parent_product_id]; } else { - $kits_id_cached[$parent_product_id] = $parent_line_id; + $sub_parents_cached[$line->fk_elementdet][$parent_product_id] = $parent_line_id; } } @@ -649,7 +654,7 @@ class Expedition extends CommonObject } // create line for a child of virtual product - if (!isset($sub_kits_id_cached[$product_child_id]) || $warehouse_id > 0) { + if (!isset($sub_kits_id_cached[$line->fk_elementdet][$product_child_id]) || $warehouse_id > 0) { $line_id = $this->create_line($warehouse_id, ($parent_line_id ? 0 : $line->origin_line_id), $product_child_qty, $line->rang, $line->array_options, $parent_line_id, $product_child_id); if ($line_id <= 0) { $error++; @@ -659,7 +664,7 @@ class Expedition extends CommonObject // if kit or not manage stock (empty incdec) if (empty($warehouse_id)) { - $sub_kits_id_cached[$product_child_id] = $line_id; + $sub_kits_id_cached[$line->fk_elementdet][$product_child_id] = $line_id; } } diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 4d44df68ce6..8fd1209d562 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -866,7 +866,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; // Actions to build doc - $upload_dir = $conf->ficheinter->dir_output; + $upload_dir = getMultidirOutput($object); $permissiontoadd = $user->hasRight('ficheinter', 'creer'); include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; @@ -1993,11 +1993,11 @@ if ($action == 'create') { * Built documents */ $filename = dol_sanitizeFileName($object->ref); - $filedir = $conf->ficheinter->dir_output."/".$filename; + $filedir = getMultidirOutput($object)."/".$filename; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $user->hasRight('ficheinter', 'lire'); $delallowed = $user->hasRight('ficheinter', 'creer'); - print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); + print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object); // Show links to link elements $tmparray = $form->showLinkToObjectBlock($object, array(), array('fichinter'), 1); @@ -2044,7 +2044,7 @@ if ($action == 'create') { // Presend form $modelmail = 'fichinter_send'; $defaulttopic = 'SendInterventionRef'; - $diroutput = $conf->ficheinter->dir_output; + $diroutput = $conf->ficheinter->multidir_output[$object->entity]; $trackid = 'int'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index e373a55ec4c..8a46c73412b 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -659,7 +659,7 @@ class Fichinter extends CommonObject $sql .= ", date_valid = '".$this->db->idate($now)."'"; $sql .= ", fk_user_valid = ".($user->id > 0 ? (int) $user->id : "null"); $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= " AND entity = ".((int) $this->entity); + $sql .= " AND entity IN (".getEntity('intervention').")"; $sql .= " AND fk_statut = 0"; @@ -770,7 +770,7 @@ class Fichinter extends CommonObject $sql .= " fk_user_modif = " . ((int) $user->id); $sql .= " WHERE rowid = " . ((int) $this->id); $sql .= " AND fk_statut > " . self::STATUS_DRAFT; - $sql .= " AND entity = " . ((int) $conf->entity); + $sql .= " AND entity IN (".getEntity('intervention').")"; if ($this->db->query($sql)) { if (!$notrigger) { diff --git a/htdocs/mrp/class/moline.class.php b/htdocs/mrp/class/moline.class.php index 1cd37b2eeeb..238bebf52fe 100644 --- a/htdocs/mrp/class/moline.class.php +++ b/htdocs/mrp/class/moline.class.php @@ -298,8 +298,10 @@ class MoLine extends CommonObjectLine $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - if ($key == 't.rowid') { + if ($key == 't.rowid' || $key == 'fk_mo' || $key == 'origin_id') { $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value); + } elseif ($key == 'origin_type') { + $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'"; } elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate((int) $value)."'"; } else { diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index e1c7a211426..a4d7ca89132 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -170,7 +170,15 @@ if (empty($reshook)) { $objectbomchildline->fetch($id_bom_line); - $TMoLines = $moline->fetchAll('DESC', 'rowid', 1, 0, array('origin_id' => $id_bom_line)); + // Find the consume line of the parent MO generated from this BOM line. + // The lookup must be scoped to the parent MO and use an exact match on origin_id/origin_type, + // otherwise the default 'origin_id LIKE %..%' filter can return an unrelated line (or none), + // which would let the child MO be created from the leftover parent POST data (duplicate MO). + $TMoLines = $moline->fetchAll('DESC', 'rowid', 1, 0, array('fk_mo' => $mo_parent->id, 'origin_id' => $id_bom_line, 'origin_type' => 'bomline')); + + if (empty($TMoLines)) { + continue; + } foreach ($TMoLines as $tmpmoline) { $_POST['fk_bom'] = $objectbomchildline->fk_bom_child; diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index f7498cbbec3..dc08e1e185b 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -634,7 +634,9 @@ if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) $arrayoftasks[$object->timespent_id]['fk_product'] = $object->timespent_fk_product; } + $pu_ht_saved = $pu_ht; // Save the base unit price (price of the selected product/service if any, 0 otherwise) foreach ($arrayoftasks as $timespent_id => $value) { + $pu_ht = $pu_ht_saved; // Reset for each line, so a line does not inherit the unit price computed for the previous one $userid = $value['user']; //$pu_ht = $value['timespent'] * $fuser->thm; @@ -643,7 +645,9 @@ if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) // If no unit price known if (empty($pu_ht)) { - $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); + if ($value['timespent']) { + $pu_ht = price2num(($value['totalvaluetodivideby3600'] / $value['timespent']), 'MU'); + } } // Add lines diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index 49f63efddc7..2e8e4da47d7 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -117,4 +117,38 @@ class CommonObjectTest extends CommonClassTest $this->assertLessThanOrEqual($result, 0); return $result; } + + /** + * testIsInt + * + * @return void + */ + public function testIsInt() + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $localobject = new Commande($db); + + // Integer types, with or without a size/unsigned suffix, must be detected. + $this->assertTrue($localobject->isInt(array('type' => 'int')), 'int'); + $this->assertTrue($localobject->isInt(array('type' => 'int(11)')), 'int(11)'); + $this->assertTrue($localobject->isInt(array('type' => 'integer')), 'integer'); + $this->assertTrue($localobject->isInt(array('type' => 'tinyint(4)')), 'tinyint(4)'); + $this->assertTrue($localobject->isInt(array('type' => 'smallint(6)')), 'smallint(6)'); + $this->assertTrue($localobject->isInt(array('type' => 'bigint(20)')), 'bigint(20)'); + // Dolibarr foreign-key column syntax "integer:Class:path" must keep being detected. + $this->assertTrue($localobject->isInt(array('type' => 'integer:User:user/class/user.class.php')), 'integer:User:...'); + + // Non-integer types must not be detected, including strings that merely contain "int". + $this->assertFalse($localobject->isInt(array('type' => 'varchar(255)')), 'varchar(255)'); + $this->assertFalse($localobject->isInt(array('type' => 'double(24,8)')), 'double(24,8)'); + $this->assertFalse($localobject->isInt(array('type' => 'date')), 'date'); + $this->assertFalse($localobject->isInt(array('type' => 'sellist:llx_c_typent:libelle:id')), 'sellist:...'); + + print __METHOD__." OK\n"; + } }