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->{useasnew} && $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);
conv_i($form->{vendor_id}), conv_i($form->{customer_id}),
$amount, $netamount, conv_date($reqdate),
$form->{taxincluded} ? 't' : 'f', $form->{shippingpoint},
- $form->{shipvia}, $form->{notes}, $form->{intnotes},
+ $form->{shipvia}, $restricter->process($form->{notes}), $form->{intnotes},
$form->{currency}, $form->{closed} ? 't' : 'f',
$form->{delivered} ? "t" : "f", $form->{proforma} ? 't' : 'f',
$quotation, conv_i($form->{department_id}),
delete $form->{convert_from_oe_ids};
@{ $form->{convert_from_oe_ids} } = @convert_from_oe_ids;
foreach (qw(ar oe)) {
- if ($form->{"convert_from_${_}_ids"}) {
+ if (!$form->{useasnew} && $form->{"convert_from_${_}_ids"}) {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => $_,
my $config_obj = SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $form->{id});
if ($config_obj) {
- my $config = { map { $_ => $config_obj->$_ } qw(active terminated periodicity start_date_as_date end_date_as_date first_billing_date_as_date extend_automatically_by ar_chart_id
+ my $config = { map { $_ => $config_obj->$_ } qw(active terminated periodicity order_value_periodicity start_date_as_date end_date_as_date first_billing_date_as_date extend_automatically_by ar_chart_id
print printer_id copies) };
$form->{periodic_invoices_config} = YAML::Dump($config);
}
if ($form->{"rowcount"} and $#ids == 0) {
$form->{"id"} = $ids[0];
undef @ids;
+ delete $form->{convert_from_oe_ids};
}
# and remember for the rest of the function
my $is_collective_order = scalar @ids;
+ $form->{useasnew} = !!$is_collective_order;
if (!$form->{id}) {
my $extra_days = $form->{type} eq 'sales_quotation' ? $::instance_conf->get_reqdate_interval : 1;
}
# delete orderitems_id in collective orders, so that they get cloned no matter what
- delete $ref->{orderitems_id} if $is_collective_order;
+ $ref->{converted_from_orderitems_id} = delete $ref->{orderitems_id} if $is_collective_order;
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};