- # link quotation items with order items
- if ($form->{"converted_from_quotation_orderitems_id_$i"}) {
- RecordLinks->create_links('dbh' => $dbh,
- 'mode' => 'ids',
- 'from_table' => 'orderitems',
- 'from_ids' => $form->{"converted_from_quotation_orderitems_id_$i"},
- 'to_table' => 'orderitems',
- 'to_id' => $orderitems_id,
- );
+ # link previous items with orderitems
+ foreach (qw(orderitems invoice)) {
+ if ($form->{"converted_from_${_}_id_$i"}) {
+ RecordLinks->create_links('dbh' => $dbh,
+ 'mode' => 'ids',
+ 'from_table' => $_,
+ 'from_ids' => $form->{"converted_from_${_}_id_$i"},
+ 'to_table' => 'orderitems',
+ 'to_id' => $orderitems_id,
+ );
+ delete $form->{"converted_from_${_}_id_$i"};
+ }