+ return $main::locale->quote_special_chars('HTML', $_[0]);
+}
+
+sub Q {
+ return $main::locale->quote_special_chars('URL@HTML', $_[0]);
+}
+
+sub E {
+ return $main::form->escape($_[0]);
+}
+
+sub NTI {
+ my ($element) = @_;
+
+ $element =~ s/tabindex\s*=\s*"\d+"//;
+ return $element;
+}
+
+sub format_dates {
+ $main::lxdebug->enter_sub();
+
+ my ($dateformat, $longformat, @indices) = @_;
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $dateformat = $myconfig{"dateformat"} unless ($dateformat);
+
+ 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] =
+ $locale->reformat_date(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i],
+ $dateformat, $longformat);
+ }
+ }
+
+ next unless (defined($form->{$idx}));
+
+ if (!ref($form->{$idx})) {
+ $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
+ $dateformat, $longformat);
+
+ } elsif (ref($form->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+ $form->{$idx}->[$i] =
+ $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
+ $dateformat, $longformat);
+ }
+ }
+ }
+
+ $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();
+}
+
+# -------------------------------------------------------------------------
+
+my %_called_subs = ();
+
+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();
+}
+
+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}));
+
+ my $onload;
+ if (0 == scalar(@{$covs})) {
+ $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
+ } elsif (1 == scalar(@{$covs})) {
+ $onload = "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");
+ $form->header();
+ print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
+ "COVS" => $covs,
+ "onload" => $onload }));
+
+ $main::lxdebug->leave_sub();
+}
+
+
+# Functions to call add routines beneath different reports
+
+sub sales_invoice {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('invoice_edit');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{script} = 'is.pl';
+ my $script = "is";
+ $form->{type} = "invoice";
+ $locale = new Locale "$myconfig{countrycode}", "$script";
+
+ require "bin/mozilla/$form->{script}";
+ &add;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub ar_transaction {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('general_ledger');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{script} = 'ar.pl';
+ my $script = "ar";
+ $locale = new Locale "$myconfig{countrycode}", "$script";
+
+ require "bin/mozilla/$form->{script}";
+ &add;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub vendor_invoice {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('invoice_edit');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{script} = 'ir.pl';
+ my $script = "ir";
+ $form->{type} = "invoice";
+ $locale = new Locale "$myconfig{countrycode}", "$script";
+
+ require "bin/mozilla/$form->{script}";
+ &add;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub ap_transaction {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('general_ledger');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{script} = 'ap.pl';
+ my $script = "ap";
+ $locale = new Locale "$myconfig{countrycode}", "$script";
+
+ require "bin/mozilla/$form->{script}";
+ &add;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub gl_transaction {
+ $main::lxdebug->enter_sub();
+
+ $main::auth->assert('general_ledger');
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{script} = 'gl.pl';
+ my $script = "gl";
+ $locale = new Locale "$myconfig{countrycode}", "$script";
+
+ require "bin/mozilla/$form->{script}";
+ &add;
+
+ $main::lxdebug->leave_sub();