+ my (%params) = @_;
+ my $sub = $params{attribute};
+ my $str = $params{object}->$sub // '';
+ my $sub_fmt = lc($params{attribute_format} // 'text');
+
+ my ($start_tag, $end_tag) = $sub_fmt eq 'html' ? ('<%', '%>') : ('<%', '%>');
+
+ $str =~ s{ ${start_tag} ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? ${end_tag} }{
+ my ($key, $format) = ($1, $3);
+ $key = $::locale->unquote_special_chars('html', $key) if $sub_fmt eq 'html';
+ my $new_value;
+
+ if (!$params{vars}->{$key}) {
+ $new_value = '';
+
+ } elsif ($format) {
+ $format = $::locale->unquote_special_chars('html', $format) if $sub_fmt eq 'html';
+
+ $new_value = DateTime::Format::Strptime->new(
+ pattern => $format,
+ locale => 'de_DE',
+ time_zone => 'local',
+ )->format_datetime($params{vars}->{$key}->[0]);
+
+ } else {
+ $new_value = $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]);
+ }
+
+ $new_value = $::locale->quote_special_chars('html', $new_value) if $sub_fmt eq 'html';
+
+ $new_value;
+
+ }eigx;
+
+ $params{object}->$sub($str);
+}
+
+sub _adjust_sellprices_for_period_lengths {
+ my (%params) = @_;
+
+ my $billing_len = $params{config}->get_billing_period_length;
+ my $order_value_len = $params{config}->get_order_value_period_length;
+
+ return if $billing_len == $order_value_len;
+
+ my $is_last_invoice_in_cycle = $params{config}->is_last_bill_date_in_order_value_cycle(date => $params{period_start_date});
+
+ _log_msg("_adjust_sellprices_for_period_lengths: period_start_date $params{period_start_date} is_last_invoice_in_cycle $is_last_invoice_in_cycle billing_len $billing_len order_value_len $order_value_len");
+
+ if ($order_value_len < $billing_len) {
+ my $num_orders_per_invoice = $billing_len / $order_value_len;
+
+ $_->sellprice($_->sellprice * $num_orders_per_invoice) for @{ $params{invoice}->items };
+
+ return;
+ }
+
+ my $num_invoices_in_cycle = $order_value_len / $billing_len;
+
+ foreach my $item (@{ $params{invoice}->items }) {
+ my $sellprice_one_invoice = $::form->round_amount($item->sellprice * $billing_len / $order_value_len, 2);
+
+ if ($is_last_invoice_in_cycle) {
+ $item->sellprice($item->sellprice - ($num_invoices_in_cycle - 1) * $sellprice_one_invoice);
+
+ } else {
+ $item->sellprice($sellprice_one_invoice);
+ }
+ }