diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index c0b6aff2d14..31c42e5ba9e 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -997,6 +997,7 @@ if (empty($reshook))
elseif ($action == 'add' && $usercancreate)
{
if ($socid > 0) $object->socid = GETPOST('socid', 'int');
+ $selectedLines = GETPOST('toselect', 'array');
$db->begin();
@@ -1586,8 +1587,11 @@ if (empty($reshook))
$fk_parent_line = 0;
$num = count($lines);
+
for ($i = 0; $i < $num; $i++)
{
+ if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines
+
// Don't add lines with qty 0 when coming from a shipment including all order lines
if ($srcobject->element == 'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) continue;
// Don't add closed lines when coming from a contract (Set constant to '0,5' to exclude also inactive lines)
@@ -3647,8 +3651,6 @@ if ($action == 'create')
print '';
print '';
- print "\n";
-
// Show origin lines
if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
print '
';
@@ -3658,12 +3660,12 @@ if ($action == 'create')
print '