$pricegroup_id *= 1;
$pricegroup_id = undef if !$pricegroup_id;
+ CVar->get_non_editable_ic_cvars(form => $form,
+ dbh => $dbh,
+ row => $i,
+ sub_module => 'orderitems',
+ may_converted_from => ['orderitems', 'invoice']);
+
my $position = $i;
# save detail record in orderitems table
- my $cvars;
if (! $form->{"orderitems_id_$i"}) {
$query = qq|SELECT nextval('orderitemsid')|;
($form->{"orderitems_id_$i"}) = selectrow_query($form, $dbh, $query);
$query = qq|INSERT INTO orderitems (id, position) VALUES (?, ?)|;
do_query($form, $dbh, $query, $form->{"orderitems_id_$i"}, conv_i($position));
-
- # get values for CVars from master data for new items
- $cvars = CVar->get_custom_variables(dbh => $dbh,
- module => 'IC',
- trans_id => $form->{"id_$i"},
- );
- } else {
- # get values for CVars from custom_variables for existing items
- $cvars = CVar->get_custom_variables(dbh => $dbh,
- module => 'IC',
- sub_module => 'orderitems',
- trans_id => $form->{"orderitems_id_$i"},
- );
}
- # map only non-editable CVars to form (editable ones are already there)
- map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars };
my $orderitems_id = $form->{"orderitems_id_$i"};
push @processed_orderitems, $orderitems_id;
my $is_collective_order = scalar @ids;
if (!$form->{id}) {
- my $wday = (localtime(time))[6];
- my $next_workday = $wday == 5 ? 3 : $wday == 6 ? 2 : 1;
+ my $extra_days = $form->{type} eq 'sales_quotation' ? $::instance_conf->get_reqdate_interval : 1;
+ my $next_workday = DateTime->today_local->add(days => $extra_days);
+ my $day_of_week = $next_workday->day_of_week;
- # if we have a client configured interval for sales quotation, we add this
- $next_workday += $::instance_conf->get_reqdate_interval if ($::instance_conf->get_reqdate_interval &&
- $form->{type} eq 'sales_quotation' );
+ $next_workday->add(days => (8 - $day_of_week)) if $day_of_week >= 6;
- $query_add = qq|, current_date AS transdate, date(current_date + interval '${next_workday} days') AS reqdate|;
+ $form->{transdate} = DateTime->today_local->to_kivitendo;
+ $form->{reqdate} = $next_workday->to_kivitendo;
}
# get default accounts
$sth->finish;
}
- my $cvars;
- if (! $form->{"orderitems_id_$i"}) {
- # get values for CVars from master data for new items
- $cvars = CVar->get_custom_variables(dbh => $dbh,
- module => 'IC',
- trans_id => $form->{"id_$i"},
- );
- } else {
- # get values for CVars from custom_variables for existing items
- $cvars = CVar->get_custom_variables(dbh => $dbh,
- module => 'IC',
- sub_module => 'orderitems',
- trans_id => $form->{"orderitems_id_$i"},
- );
- }
- # map only non-editable CVars to form (editable ones are already there)
- map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars };
+ CVar->get_non_editable_ic_cvars(form => $form,
+ dbh => $dbh,
+ row => $i,
+ sub_module => 'orderitems',
+ may_converted_from => ['orderitems', 'invoice']);
push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)