kivitendo/bin/mozilla/common.pl @ ed76c91e
ed42de15 | Moritz Bunkus | #=====================================================================
|
||
# LX-Office ERP
|
||||
# Copyright (C) 2004
|
||||
# Based on SQL-Ledger Version 2.1.9
|
||||
# Web http://www.lx-office.org
|
||||
######################################################################
|
||||
#
|
||||
# Stuff that can be used from other modules
|
||||
#
|
||||
######################################################################
|
||||
54e4131e | Moritz Bunkus | use SL::Common;
|
||
1e513d1d | Moritz Bunkus | use SL::DB::Helper::Mappings;
|
||
8c7e4493 | Moritz Bunkus | use SL::DBUtils;
|
||
use SL::Form;
|
||||
6b293028 | Moritz Bunkus | use SL::MoreCommon;
|
||
39294de3 | Moritz Bunkus | use SL::Helper::Flash;
|
||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | use strict;
|
||
828bd683 | Moritz Bunkus | sub build_std_url {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub(2);
|
||
my $form = $main::form;
|
||||
828bd683 | Moritz Bunkus | |||
0c27df9b | Moritz Bunkus | my $script = $form->{script};
|
||
my @parts;
|
||||
8c7e4493 | Moritz Bunkus | foreach my $key (@_) {
|
||
828bd683 | Moritz Bunkus | next unless ($key);
|
||
0c27df9b | Moritz Bunkus | if ($key =~ /(.*?)=(.*)/) {
|
||
if ($1 eq 'script') {
|
||||
$script = $2;
|
||||
} else {
|
||||
push @parts, $key;
|
||||
}
|
||||
828bd683 | Moritz Bunkus | } else {
|
||
8c7e4493 | Moritz Bunkus | foreach my $var ($form->flatten_variables($key)) {
|
||
push @parts, E($var->{key}) . '=' . E($var->{value});
|
||||
}
|
||||
828bd683 | Moritz Bunkus | }
|
||
}
|
||||
0c27df9b | Moritz Bunkus | my $url = "${script}?" . join('&', @parts);
|
||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub(2);
|
||
828bd683 | Moritz Bunkus | |||
return $url;
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
ed42de15 | Moritz Bunkus | |||
83914eeb | Moritz Bunkus | sub select_part {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
83914eeb | Moritz Bunkus | |||
my ($callback_sub, @parts) = @_;
|
||||
9257ca9a | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
83914eeb | Moritz Bunkus | my $remap_parts_id = 0;
|
||
if (defined($parts[0]->{parts_id}) && !defined($parts[0]->{id})) {
|
||||
$remap_parts_id = 1;
|
||||
map { $_->{id} = $_->{parts_id}; } @parts;
|
||||
}
|
||||
my $remap_partnumber = 0;
|
||||
if (defined($parts[0]->{partnumber}) && !defined($parts[0]->{number})) {
|
||||
$remap_partnumber = 1;
|
||||
map { $_->{number} = $_->{partnumber}; } @parts;
|
||||
}
|
||||
my $has_charge = 0;
|
||||
if (defined($parts[0]->{chargenumber})) {
|
||||
$has_charge = 1;
|
||||
map { $_->{has_charge} = 1; } @parts;
|
||||
}
|
||||
096f9e3e | Bernd Bleßmann | my $has_bestbefore = 0;
|
||
if (defined($parts[0]->{bestbefore})) {
|
||||
$has_bestbefore = 1;
|
||||
map { $_->{has_bestbefore} = 1; } @parts;
|
||||
}
|
||||
cc7a38de | Geoffrey Richardson | my $has_ean = 0;
|
||
if (defined($parts[0]->{ean})) {
|
||||
$has_ean = 1;
|
||||
map { $_->{has_ean} = 1; } @parts;
|
||||
}
|
||||
83914eeb | Moritz Bunkus | |||
my $old_form = save_form();
|
||||
$form->header();
|
||||
print $form->parse_html_template("generic/select_part",
|
||||
{ "PARTS" => \@parts,
|
||||
"old_form" => $old_form,
|
||||
"title" => $locale->text("Select a part"),
|
||||
"nextsub" => "select_part_internal",
|
||||
"callback_sub" => $callback_sub,
|
||||
"has_charge" => $has_charge,
|
||||
096f9e3e | Bernd Bleßmann | "has_bestbefore" => $has_bestbefore,
|
||
b65a230d | Sven Schöling | "has_ean" => $has_ean,
|
||
83914eeb | Moritz Bunkus | "remap_parts_id" => $remap_parts_id,
|
||
"remap_partnumber" => $remap_partnumber });
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
83914eeb | Moritz Bunkus | }
|
||
sub select_part_internal {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
83914eeb | Moritz Bunkus | |||
my ($new_item, $callback_sub);
|
||||
893bff3a | Moritz Bunkus | my $re = "^new_.*_$form->{selection}\$";
|
||
83914eeb | Moritz Bunkus | |||
foreach (grep /$re/, keys %{ $form }) {
|
||||
my $new_key = $_;
|
||||
$new_key =~ s/^new_//;
|
||||
$new_key =~ s/_\d+$//;
|
||||
$new_item->{$new_key} = $form->{$_};
|
||||
}
|
||||
if ($form->{remap_parts_id}) {
|
||||
$new_item->{parts_id} = $new_item->{id};
|
||||
delete $new_item->{id};
|
||||
}
|
||||
if ($form->{remap_partnumber}) {
|
||||
$new_item->{partnumber} = $new_item->{number};
|
||||
delete $new_item->{number};
|
||||
}
|
||||
9257ca9a | Sven Schöling | $callback_sub = $form->{callback_sub};
|
||
83914eeb | Moritz Bunkus | |||
restore_form($form->{old_form});
|
||||
call_sub($callback_sub, $new_item);
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
83914eeb | Moritz Bunkus | }
|
||
sub part_selection_internal {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
83914eeb | Moritz Bunkus | |||
9257ca9a | Sven Schöling | my $order_by = "description";
|
||
83914eeb | Moritz Bunkus | $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
|
||
9257ca9a | Sven Schöling | my $order_dir = 1;
|
||
83914eeb | Moritz Bunkus | $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
|
||
94f3406d | Moritz Bunkus | my %options;
|
||
83914eeb | Moritz Bunkus | |||
94f3406d | Moritz Bunkus | foreach my $opt (split m/:/, $form->{options}) {
|
||
if ($opt =~ /=/) {
|
||||
my ($key, $value) = split m/=/, $opt, 2;
|
||||
$options{$key} = $value;
|
||||
} else {
|
||||
$options{$opt} = 1;
|
||||
}
|
||||
}
|
||||
358f1ed4 | Geoffrey Richardson | map { $form->{$_} = $options{$_} if ($options{$_}) } qw(no_services no_assemblies assemblies click_button);
|
||
83914eeb | Moritz Bunkus | |||
9257ca9a | Sven Schöling | my $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
|
||
83914eeb | Moritz Bunkus | |||
if (0 == scalar(@{$parts})) {
|
||||
$form->show_generic_information($locale->text("No part was found matching the search parameters."));
|
||||
} elsif (1 == scalar(@{$parts})) {
|
||||
18407da4 | Sven Schöling | $::request->{layout}->add_javascripts_inline("part_selected('1')");
|
||
83914eeb | Moritz Bunkus | }
|
||
map { $parts->[$_]->{selected} = $_ ? 0 : 1; } (0..$#{$parts});
|
||||
my $callback = build_std_url('action=part_selection_internal', qw(partnumber description input_partnumber input_description input_partsid),
|
||||
grep({ /^[fl]_/ } keys %{ $form }));
|
||||
my @header_sort = qw(partnumber description);
|
||||
my %header_title = ( "partnumber" => $locale->text("Part Number"),
|
||||
4b937d1a | Sven Donath | "description" => $locale->text("Part Description"),
|
||
83914eeb | Moritz Bunkus | );
|
||
my @header =
|
||||
map(+{ "column_title" => $header_title{$_},
|
||||
"column" => $_,
|
||||
"callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
|
||||
},
|
||||
@header_sort);
|
||||
94f3406d | Moritz Bunkus | $form->{formname} ||= 'Form';
|
||
83914eeb | Moritz Bunkus | $form->{title} = $locale->text("Select a part");
|
||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
83914eeb | Moritz Bunkus | print $form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
|
||
18407da4 | Sven Schöling | "PARTS" => $parts, });
|
||
83914eeb | Moritz Bunkus | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
83914eeb | Moritz Bunkus | }
|
||
# -------------------------------------------------------------------------
|
||||
54e4131e | Moritz Bunkus | sub delivery_customer_selection {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | my $order_by = "name";
|
||
54e4131e | Moritz Bunkus | $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
|
||
9257ca9a | Sven Schöling | my $order_dir = 1;
|
||
54e4131e | Moritz Bunkus | $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
|
||
9257ca9a | Sven Schöling | my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
|
||
54e4131e | Moritz Bunkus | map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
|
||
9257ca9a | Sven Schöling | |||
54e4131e | Moritz Bunkus | if (0 == scalar(@{$delivery})) {
|
||
$form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
|
||||
} elsif (1 == scalar(@{$delivery})) {
|
||||
18407da4 | Sven Schöling | $::request->{layout}->add_javascripts_inline("customer_selected('1')");
|
||
54e4131e | Moritz Bunkus | }
|
||
my $callback = "$form->{script}?action=delivery_customer_selection&";
|
||||
map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
|
||||
8c7e4493 | Moritz Bunkus | (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
|
||
54e4131e | Moritz Bunkus | |||
my @header_sort = qw(name customernumber address);
|
||||
my %header_title = ( "name" => $locale->text("Name"),
|
||||
"customernumber" => $locale->text("Customer Number"),
|
||||
"address" => $locale->text("Address"),
|
||||
);
|
||||
my @header =
|
||||
map(+{ "column_title" => $header_title{$_},
|
||||
"column" => $_,
|
||||
"callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
|
||||
},
|
||||
@header_sort);
|
||||
$form->{"title"} = $locale->text("Select a Customer");
|
||||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
9aaca433 | Moritz Bunkus | print $form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
|
||
18407da4 | Sven Schöling | "DELIVERY" => $delivery, });
|
||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
54e4131e | Moritz Bunkus | sub vendor_selection {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | my $order_by = "name";
|
||
54e4131e | Moritz Bunkus | $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
|
||
9257ca9a | Sven Schöling | my $order_dir = 1;
|
||
54e4131e | Moritz Bunkus | $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
|
||
9257ca9a | Sven Schöling | my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
|
||
54e4131e | Moritz Bunkus | map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
|
||
9257ca9a | Sven Schöling | |||
54e4131e | Moritz Bunkus | if (0 == scalar(@{$vendor})) {
|
||
$form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
|
||||
} elsif (1 == scalar(@{$vendor})) {
|
||||
18407da4 | Sven Schöling | $::request->{layout}->add_javascripts_inline("vendor_selected('1')");
|
||
54e4131e | Moritz Bunkus | }
|
||
my $callback = "$form->{script}?action=vendor_selection&";
|
||||
map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
|
||||
8c7e4493 | Moritz Bunkus | (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
|
||
54e4131e | Moritz Bunkus | |||
my @header_sort = qw(name customernumber address);
|
||||
my %header_title = ( "name" => $locale->text("Name"),
|
||||
"customernumber" => $locale->text("Customer Number"),
|
||||
"address" => $locale->text("Address"),
|
||||
);
|
||||
my @header =
|
||||
map(+{ "column_title" => $header_title{$_},
|
||||
"column" => $_,
|
||||
"callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
|
||||
},
|
||||
@header_sort);
|
||||
$form->{"title"} = $locale->text("Select a Customer");
|
||||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
9aaca433 | Moritz Bunkus | print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
|
||
18407da4 | Sven Schöling | "VENDOR" => $vendor, });
|
||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
54e4131e | Moritz Bunkus | sub calculate_qty {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
54e4131e | Moritz Bunkus | |||
$form->{formel} =~ s/\r\n//g;
|
||||
my ($variable_string, $formel) = split /###/,$form->{formel};
|
||||
9257ca9a | Sven Schöling | my @variable;
|
||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | foreach my $item (split m/;/, $variable_string) {
|
||
3bd1773c | Sven Schöling | next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
|
||
push @variable, {
|
||||
description => $1,
|
||||
name => $2,
|
||||
unit => $3,
|
||||
};
|
||||
54e4131e | Moritz Bunkus | }
|
||
my @header_sort = qw(variable value unit);
|
||||
3bd1773c | Sven Schöling | my %header_title = (
|
||
variable => $locale->text("Variable"),
|
||||
value => $locale->text("Value"),
|
||||
unit => $locale->text("Unit"),
|
||||
);
|
||||
my @header = map +{
|
||||
column_title => $header_title{$_},
|
||||
column => $_,
|
||||
}, @header_sort;
|
||||
54e4131e | Moritz Bunkus | |||
8c7e4493 | Moritz Bunkus | $form->{formel} = $formel;
|
||
3bd1773c | Sven Schöling | $form->{title} = $locale->text("Please enter values");
|
||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
3bd1773c | Sven Schöling | print $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
|
||
18407da4 | Sven Schöling | "VARIABLES" => \@variable, });
|
||
54e4131e | Moritz Bunkus | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
aacd5750 | Moritz Bunkus | sub H {
|
||
9257ca9a | Sven Schöling | return $main::locale->quote_special_chars('HTML', $_[0]);
|
||
aacd5750 | Moritz Bunkus | }
|
||
4826a1d1 | Moritz Bunkus | sub Q {
|
||
9257ca9a | Sven Schöling | return $main::locale->quote_special_chars('URL@HTML', $_[0]);
|
||
4826a1d1 | Moritz Bunkus | }
|
||
828bd683 | Moritz Bunkus | sub E {
|
||
9257ca9a | Sven Schöling | return $main::form->escape($_[0]);
|
||
828bd683 | Moritz Bunkus | }
|
||
cfc6a60d | Moritz Bunkus | sub NTI {
|
||
my ($element) = @_;
|
||||
$element =~ s/tabindex\s*=\s*"\d+"//;
|
||||
return $element;
|
||||
}
|
||||
acc2b53b | Moritz Bunkus | sub format_dates {
|
||
bc433711 | Moritz Bunkus | return $::form->format_dates(@_);
|
||
acc2b53b | Moritz Bunkus | }
|
||
sub reformat_numbers {
|
||||
463ea852 | Moritz Bunkus | return $::form->reformat_numbers(@_);
|
||
ebef09a8 | Thomas Kasulke | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
9484d564 | Moritz Bunkus | 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");
|
||||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
9484d564 | Moritz Bunkus | 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,
|
||||
ddb162b6 | Sven Schöling | uc($sort)."BY" => $sortby,
|
||
9484d564 | Moritz Bunkus | } );
|
||
$dbh->disconnect();
|
||||
$main::lxdebug->leave_sub();
|
||||
}
|
||||
# -------------------------------------------------------------------------
|
||||
40782548 | Moritz Bunkus | sub call_sub {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
40782548 | Moritz Bunkus | |||
my $name = shift;
|
||||
9257ca9a | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
40782548 | Moritz Bunkus | 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));
|
||||
}
|
||||
9257ca9a | Sven Schöling | {
|
||
no strict "refs";
|
||||
&{ $name }(@_);
|
||||
}
|
||||
40782548 | Moritz Bunkus | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
40782548 | Moritz Bunkus | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
fb4d2ffa | Moritz Bunkus | sub show_vc_details {
|
||
b65a230d | Sven Schöling | $main::lxdebug->enter_sub();
|
||
9257ca9a | Sven Schöling | |||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
fb4d2ffa | Moritz Bunkus | |||
$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});
|
||||
c853dd6e | Thomas Heck | $form->{discount_as_percent} = $form->format_amount(\%::myconfig, $form->parse_amount(\%::myconfig, $form->{discount}) * 100, 2);
|
||
fb4d2ffa | Moritz Bunkus | |||
$form->{title} = $form->{vc} eq "customer" ?
|
||||
$locale->text("Customer details") : $locale->text("Vendor details");
|
||||
ddb162b6 | Sven Schöling | $form->header(no_layout => 1);
|
||
9aaca433 | Moritz Bunkus | print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
|
||
fb4d2ffa | Moritz Bunkus | |||
b65a230d | Sven Schöling | $main::lxdebug->leave_sub();
|
||
fb4d2ffa | Moritz Bunkus | }
|
||
8c7e4493 | Moritz Bunkus | # -------------------------------------------------------------------------
|
||
sub retrieve_partunits {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
8c7e4493 | Moritz Bunkus | |||
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}"}};
|
||||
}
|
||||
}
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
8c7e4493 | Moritz Bunkus | }
|
||
# -------------------------------------------------------------------------
|
||||
2e07a0cd | Thomas Kasulke | sub mark_as_paid_common {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
8c7e4493 | Moritz Bunkus | |||
2e07a0cd | Thomas Kasulke | my ($myconfig, $db_name) = @_;
|
||
9257ca9a | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
2e07a0cd | Thomas Kasulke | if($form->{mark_as_paid}) {
|
||
my $dbh ||= $form->get_standard_dbh($myconfig);
|
||||
40c2c37c | Moritz Bunkus | my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|;
|
||
2e07a0cd | Thomas Kasulke | do_query($form, $dbh, $query, $form->{id});
|
||
$dbh->commit();
|
||||
$form->redirect($locale->text("Marked as paid"));
|
||||
8c7e4493 | Moritz Bunkus | |||
} else {
|
||||
my $referer = $ENV{HTTP_REFERER};
|
||||
9257ca9a | Sven Schöling | my $script;
|
||
my $callback;
|
||||
f52b5731 | Philip Reetz | if ($referer =~ /action/) {
|
||
$referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/;
|
||||
5562f8b4 | Philip Reetz | $script = $1;
|
||
$callback = $2;
|
||||
c65e0af9 | Peter Schulgin | } elsif ($referer =~ /RESTORE_FORM_FROM_SESSION_ID/){
|
||
$referer =~ /^(.*)\?RESTORE_FORM_FROM_SESSION_ID\=(.*)$/;
|
||||
$script = $1;
|
||||
$callback = "";
|
||||
5562f8b4 | Philip Reetz | } else {
|
||
$script = $referer;
|
||||
$callback = "";
|
||||
}
|
||||
$referer = $script . "?action=mark_as_paid&mark_as_paid=1&id=$form->{id}" . $callback;
|
||||
2e07a0cd | Thomas Kasulke | $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();">|;
|
||||
8c7e4493 | Moritz Bunkus | }
|
||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
2e07a0cd | Thomas Kasulke | }
|
||
91ab1ef6 | Sven Schöling | sub cov_selection_internal {
|
||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
91ab1ef6 | Sven Schöling | |||
9257ca9a | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
my $order_by = "name";
|
||||
91ab1ef6 | Sven Schöling | $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
|
||
9257ca9a | Sven Schöling | my $order_dir = 1;
|
||
91ab1ef6 | Sven Schöling | $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
|
||
my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
|
||||
9257ca9a | Sven Schöling | my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
|
||
91ab1ef6 | Sven Schöling | map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
|
||
9257ca9a | Sven Schöling | |||
91ab1ef6 | Sven Schöling | if (0 == scalar(@{$covs})) {
|
||
$form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
|
||||
} elsif (1 == scalar(@{$covs})) {
|
||||
18407da4 | Sven Schöling | $::request->{layout}->add_javascripts_inline("cov_selected('1')");
|
||
91ab1ef6 | Sven Schöling | }
|
||
my $callback = "$form->{script}?action=cov_selection_internal&";
|
||||
map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
|
||||
5b22b6b5 | Moritz Bunkus | (qw(name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
|
||
91ab1ef6 | Sven Schöling | |||
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;
|
||||
e09347c8 | Geoffrey Richardson | $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_gender cp_title cp_givenname cp_name);
|
||
91ab1ef6 | Sven Schöling | $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,
|
||||
18407da4 | Sven Schöling | "COVS" => $covs, }));
|
||
91ab1ef6 | Sven Schöling | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
91ab1ef6 | Sven Schöling | }
|
||
ea2e84cc | Philip Reetz | |||
# Functions to call add routines beneath different reports
|
||||
sub sales_invoice {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
ea2e84cc | Philip Reetz | |||
2827b2dc | Moritz Bunkus | print $::form->redirect_header('is.pl?action=add&type=invoice');
|
||
ea2e84cc | Philip Reetz | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ea2e84cc | Philip Reetz | }
|
||
sub ar_transaction {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
ea2e84cc | Philip Reetz | |||
2827b2dc | Moritz Bunkus | print $::form->redirect_header('ar.pl?action=add');
|
||
ea2e84cc | Philip Reetz | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ea2e84cc | Philip Reetz | }
|
||
sub vendor_invoice {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
ea2e84cc | Philip Reetz | |||
2827b2dc | Moritz Bunkus | print $::form->redirect_header('ir.pl?action=add&type=invoice');
|
||
ea2e84cc | Philip Reetz | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ea2e84cc | Philip Reetz | }
|
||
sub ap_transaction {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
ea2e84cc | Philip Reetz | |||
2827b2dc | Moritz Bunkus | print $::form->redirect_header('ap.pl?action=add');
|
||
ea2e84cc | Philip Reetz | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ea2e84cc | Philip Reetz | }
|
||
sub gl_transaction {
|
||||
9257ca9a | Sven Schöling | $main::lxdebug->enter_sub();
|
||
ea2e84cc | Philip Reetz | |||
2827b2dc | Moritz Bunkus | print $::form->redirect_header('gl.pl?action=add');
|
||
ea2e84cc | Philip Reetz | |||
9257ca9a | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ea2e84cc | Philip Reetz | }
|
||
1e513d1d | Moritz Bunkus | sub db {
|
||
goto &SL::DB::Helper::Mappings::db;
|
||||
f97b0778 | Sven Schöling | }
|
||
ed42de15 | Moritz Bunkus | 1;
|