+ $main::lxdebug->leave_sub();
+}
+
+sub reformat_numbers {
+ $main::lxdebug->enter_sub();
+
+ my ($numberformat, $places, @indices) = @_;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ return $main::lxdebug->leave_sub()
+ if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
+
+ foreach my $idx (@indices) {
+ if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
+ for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) {
+ $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->parse_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i]);
+ }
+ }
+
+ next unless (defined($form->{$idx}));
+
+ if (!ref($form->{$idx})) {
+ $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
+
+ } elsif (ref($form->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+ $form->{$idx}->[$i] =
+ $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
+ }
+ }
+ }
+
+ my $saved_numberformat = $myconfig{"numberformat"};
+ $myconfig{"numberformat"} = $numberformat;
+
+ foreach my $idx (@indices) {
+ if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
+ for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) {
+ $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->format_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places);
+ }
+ }
+
+ next unless (defined($form->{$idx}));
+
+ if (!ref($form->{$idx})) {
+ $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
+
+ } elsif (ref($form->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+ $form->{$idx}->[$i] =
+ $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
+ }
+ }
+ }
+
+ $myconfig{"numberformat"} = $saved_numberformat;
+
+ $main::lxdebug->leave_sub();
+}
+
+# -------------------------------------------------------------------------
+
+sub show_history {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ my $dbh = $form->dbconnect(\%myconfig);
+ my ($sort, $sortby) = split(/\-\-/, $form->{order});
+ $sort =~ s/.*\.(.*)/$1/;
+
+ $form->{title} = $locale->text("History");
+ $form->header();
+ print $form->parse_html_template( "common/show_history", {
+ "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}),
+ "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
+ uc($sort) => 1,
+ uc($sort)."BY" => $sortby
+ } );
+
+ $dbh->disconnect();
+ $main::lxdebug->leave_sub();
+}
+
+# -------------------------------------------------------------------------
+
+sub call_sub {
+ $main::lxdebug->enter_sub();
+
+ my $name = shift;
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ if (!$name) {
+ $form->error($locale->text("Trying to call a sub without a name"));
+ }
+
+ $name =~ s/[^a-zA-Z0-9_]//g;
+
+ if (!defined(&{ $name })) {
+ $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
+ }
+
+ $::called_subs{$name}++;
+ confess "RECURSION DETECTION: call_sub($name) called " . $::called_subs{$name} . " time(s)" if $::called_subs{$name} > 10;
+
+ {
+ no strict "refs";
+ &{ $name }(@_);
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+# -------------------------------------------------------------------------
+
+sub show_vc_details {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
+ $form->isblank("vc_id",
+ $form->{vc} eq "customer" ?
+ $locale->text("No customer has been selected yet.") :
+ $locale->text("No vendor has been selected yet."));
+
+ Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
+
+ $form->{title} = $form->{vc} eq "customer" ?
+ $locale->text("Customer details") : $locale->text("Vendor details");
+ $form->header();
+ print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
+
+ $main::lxdebug->leave_sub();
+}
+
+# -------------------------------------------------------------------------
+
+sub retrieve_partunits {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+
+ my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
+
+ if (@part_ids) {
+ my %partunits = IO->retrieve_partunits('part_ids' => \@part_ids);
+
+ foreach my $i (1..$form->{rowcount}) {
+ next unless ($form->{"id_${i}"});
+ $form->{"partunit_${i}"} = $partunits{$form->{"id_${i}"}};
+ }
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+# -------------------------------------------------------------------------
+
+sub mark_as_paid_common {
+ $main::lxdebug->enter_sub();
+
+ my ($myconfig, $db_name) = @_;
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ if($form->{mark_as_paid}) {
+ my $dbh ||= $form->get_standard_dbh($myconfig);
+ my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|;
+ do_query($form, $dbh, $query, $form->{id});
+ $dbh->commit();
+ $form->redirect($locale->text("Marked as paid"));
+
+ } else {
+ my $referer = $ENV{HTTP_REFERER};
+ my $script;
+ my $callback;
+ if ($referer =~ /action/) {
+ $referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/;
+ $script = $1;
+ $callback = $2;
+ } else {
+ $script = $referer;
+ $callback = "";
+ }
+ $referer = $script . "?action=mark_as_paid&mark_as_paid=1&id=$form->{id}" . $callback;
+ $form->header();
+ print qq|<body>|;
+ print qq|<p><b>|.$locale->text('Mark as paid?').qq|</b></p>|;
+ print qq|<input type="button" value="|.$locale->text('yes').qq|" onclick="document.location.href='|.$referer.qq|'"> |;
+ print qq|<input type="button" value="|.$locale->text('no').qq|" onclick="javascript:history.back();">|;
+ print qq|</body></html>|;
+ }
+
+ $main::lxdebug->leave_sub();
+}