+ $form->header(no_layout => 1);
+ 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}) {
+ SL::DB->client->with_transaction(sub {
+ my $dbh ||= SL::DB->client->dbh;
+ my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|;
+ do_query($form, $dbh, $query, $form->{id});
+ 1;
+ }) or do { $::form->error(SL::DB->client->error) };
+ $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;
+ } elsif ($referer =~ /RESTORE_FORM_FROM_SESSION_ID/){
+ $referer =~ /^(.*)\?RESTORE_FORM_FROM_SESSION_ID\=(.*)$/;
+ $script = $1;
+ $callback = "";
+ } else {
+ $script = $referer;
+ $callback = "";
+ }
+ $referer = $script . "?action=mark_as_paid&mark_as_paid=1&id=$form->{id}" . $callback;
+ $form->header();
+ 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();">|;
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub cov_selection_internal {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ my $order_by = "name";
+ $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
+ my $order_dir = 1;
+ $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
+
+ my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
+
+ my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
+ map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
+
+ if (0 == scalar(@{$covs})) {
+ $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
+ } elsif (1 == scalar(@{$covs})) {
+ $::request->{layout}->add_javascripts_inline("cov_selected('1')");
+ }
+
+ my $callback = "$form->{script}?action=cov_selection_internal&";
+ map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
+ (qw(name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
+
+ my @header_sort = qw(name address contact);
+ my %header_title = ( "name" => $locale->text("Name"),
+ "address" => $locale->text("Address"),
+ "contact" => $locale->text("Contact"),
+ );
+
+ my @header =
+ map(+{ "column_title" => $header_title{$_},
+ "column" => $_,
+ "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
+ },
+ @header_sort);
+
+ foreach my $cov (@{ $covs }) {
+ $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
+ $cov->{address} =~ s{^,}{}x;
+ $cov->{address} =~ s{\ +}{\ }gx;
+
+ $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_gender cp_title cp_givenname cp_name);
+ $cov->{contact} =~ s{\ +}{\ }gx;
+ }
+
+ $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");