dbh => $dbh,
row => $i,
sub_module => 'delivery_order_items',
- may_converted_from => ['orderitems']);
+ may_converted_from => ['orderitems', 'delivery_order_items']);
my $position = $i;
name_prefix => 'ic_',
name_postfix => "_$i",
dbh => $dbh);
+
# link order items with doi, for future extension look at foreach IS.pm
- if ($form->{"converted_from_orderitems_id_$i"}) {
+ if (!$form->{saveasnew} && $form->{"converted_from_orderitems_id_$i"}) {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => 'orderitems',
'to_table' => 'delivery_order_items',
'to_id' => $form->{"delivery_order_items_id_$i"},
);
- delete $form->{"converted_from_orderitems_id_$i"};
}
+ delete $form->{"converted_from_orderitems_id_$i"};
}
# 1. search for orphaned dois; processed_dois may be empty (no transfer) TODO: be supersafe and alter same statement for doi and oi
dbh => $dbh,
row => $i,
sub_module => 'delivery_order_items',
- may_converted_from => ['orderitems']);
+ may_converted_from => ['orderitems', 'delivery_order_items']);
push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)
dbh => $dbh,
row => $i,
sub_module => 'invoice',
- may_converted_from => ['delivery_order_items', 'orderitems']);
+ may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']);
if (!$form->{"invoice_id_$i"}) {
# there is no persistent id, therefore create one with all necessary constraints
name_prefix => 'ic_',
name_postfix => "_$i",
dbh => $dbh);
+
# link previous items with invoice items See IS.pm (no credit note -> no invoice item)
foreach (qw(delivery_order_items orderitems)) {
- if ($form->{"converted_from_${_}_id_$i"}) {
+ if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => $_,
'to_table' => 'invoice',
'to_id' => $form->{"invoice_id_$i"},
);
- delete $form->{"converted_from_${_}_id_$i"};
}
+ delete $form->{"converted_from_${_}_id_$i"};
}
}
}
# link previous items with invoice items
foreach (qw(delivery_order_items orderitems invoice)) {
- if ($form->{"converted_from_${_}_id_$i"}) {
+ if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => $_,
'to_table' => 'invoice',
'to_id' => $form->{"invoice_id_$i"},
);
- delete $form->{"converted_from_${_}_id_$i"};
}
+ delete $form->{"converted_from_${_}_id_$i"};
}
}
name_prefix => 'ic_',
name_postfix => "_$i",
dbh => $dbh);
+
# link previous items with orderitems
foreach (qw(orderitems invoice)) {
- if ($form->{"converted_from_${_}_id_$i"}) {
+ if (!$form->{saveasnew} && $form->{"converted_from_${_}_id_$i"}) {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => $_,
'to_table' => 'orderitems',
'to_id' => $orderitems_id,
);
- delete $form->{"converted_from_${_}_id_$i"};
}
+ delete $form->{"converted_from_${_}_id_$i"};
}
}
}
+
# search for orphaned ids
$query = sprintf 'SELECT id FROM orderitems WHERE trans_id = ? AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_orderitems;
@values = (conv_i($form->{id}), map { conv_i($_) } @processed_orderitems);
$form->{delivered} = 0;
map { delete $form->{$_} } qw(printed emailed queued);
delete @{ $form }{ grep { m/^stock_(?:in|out)_\d+/ } keys %{ $form } };
- delete $form->{"delivery_order_items_id_$_"} for 1 .. $form->{"rowcount"};
+ $form->{"converted_from_delivery_order_items_id_$_"} = delete $form->{"delivery_order_items_id_$_"} for 1 .. $form->{"rowcount"};
# Let kivitendo assign a new order number if the user hasn't changed the
# previous one. If it has been changed manually then use it as-is.
$form->{donumber} =~ s/^\s*//g;
push @hidden_vars, qw(orderitems_id converted_from_orderitems_id converted_from_invoice_id);
}
if ($is_invoice) {
- push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id);
+ push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id converted_from_invoice_id);
}
if ($::form->{type} =~ /credit_note/) {
push @hidden_vars, qw(invoice_id converted_from_invoice_id);
map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost);
push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
- push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id);
+ push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id converted_from_delivery_order_items_id);
}
my @HIDDENS = map { value => $_}, (
max_dunning_level dunning_amount
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
- convert_from_do_ids convert_from_oe_ids show_details gldate
+ convert_from_do_ids convert_from_oe_ids show_details gldate useasnew
), @custom_hiddens,
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
$form->{paidaccounts} = 1;
$form->{rowcount}--;
$form->{invdate} = $form->current_date(\%myconfig);
- delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+ $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+ $form->{useasnew} = 1;
&display_form;
$main::lxdebug->leave_sub();
max_dunning_level dunning_amount
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
shiptoemail shiptodepartment_1 shiptodepartment_2 shiptocp_gender message email subject cc bcc taxaccounts cursor_fokus
- convert_from_do_ids convert_from_oe_ids convert_from_ar_ids
+ convert_from_do_ids convert_from_oe_ids convert_from_ar_ids useasnew
invoice_id
show_details
), @custom_hiddens,
$form->{employee_id} = SL::DB::Manager::Employee->current->id;
$form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
$form->{exchangerate} = $form->{forex} if $form->{forex};
- delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+ $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+ $form->{useasnew} = 1;
&display_form;
$main::lxdebug->leave_sub();
$form->{saveasnew} = 1;
map { delete $form->{$_} } qw(printed emailed queued delivered closed);
- delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
+ $form->{"converted_from_orderitems_id_$_"} = delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
# Let kivitendo assign a new order number if the user hasn't changed the
# previous one. If it has been changed manually then use it as-is.