package Form;
+use Carp;
use Data::Dumper;
use CGI;
use SL::DB;
use SL::DBConnect;
use SL::DBUtils;
+use SL::DB::Customer;
use SL::DB::Default;
+use SL::DB::PaymentTerm;
+use SL::DB::Vendor;
use SL::DO;
use SL::IC;
use SL::IS;
# this should gradually move to the layouts that need it
$layout->use_stylesheet("$_.css") for qw(
main menu list_accounts jquery.autocomplete
- jquery.multiselect2side frame_header/header
+ jquery.multiselect2side
ui-lightness/jquery-ui
jquery-ui.custom jqModal
);
$layout->use_javascript("$_.js") for (qw(
jquery jquery-ui jquery.cookie jqModal jquery.checkall jquery.download
- common part_selection switchmenuframe
+ common part_selection switchmenuframe autocomplete_part
), "jquery/ui/i18n/jquery.ui.datepicker-$::myconfig{countrycode}");
$self->{favicon} ||= "favicon.ico";
close $temp_fh;
(undef, undef, $self->{template_meta}{tmpfile}) = File::Spec->splitpath( $self->{tmpfile} );
- if ($template->uses_temp_file() || $self->{media} eq 'email') {
- $out = $self->{OUT};
- $out_mode = $self->{OUT_MODE} || '>';
- $self->{OUT} = "$self->{tmpfile}";
- $self->{OUT_MODE} = '>';
- }
+ $out = $self->{OUT};
+ $out_mode = $self->{OUT_MODE} || '>';
+ $self->{OUT} = "$self->{tmpfile}";
+ $self->{OUT_MODE} = '>';
my $result;
my $command_formatter = sub {
close OUT if $self->{OUT};
- Common::copy_file_to_webdav_folder($self) if ($::instance_conf->get_webdav
- and $::instance_conf->get_webdav_documents and not $self->{preview});
+ my $copy_to_webdav = $::instance_conf->get_webdav && $::instance_conf->get_webdav_documents && !$self->{preview};
if ($self->{media} eq 'file') {
copy(join('/', $self->{cwd}, $userspath, $self->{tmpfile}), $out =~ m|^/| ? $out : join('/', $self->{cwd}, $out)) if $template->uses_temp_file;
+ Common::copy_file_to_webdav_folder($self) if $copy_to_webdav;
$self->cleanup;
chdir("$self->{cwd}");
return;
}
- if ($template->uses_temp_file() || $self->{media} eq 'email') {
+ Common::copy_file_to_webdav_folder($self) if $copy_to_webdav;
- if ($self->{media} eq 'email') {
+ if ($self->{media} eq 'email') {
- my $mail = new Mailer;
+ my $mail = new Mailer;
- map { $mail->{$_} = $self->{$_} }
- qw(cc bcc subject message version format);
- $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
- $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
- $mail->{fileid} = time() . '.' . $$ . '.';
- $myconfig->{signature} =~ s/\r//g;
+ map { $mail->{$_} = $self->{$_} }
+ qw(cc bcc subject message version format);
+ $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
+ $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
+ $mail->{fileid} = time() . '.' . $$ . '.';
+ $myconfig->{signature} =~ s/\r//g;
- # if we send html or plain text inline
- if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
- $mail->{contenttype} = "text/html";
- $mail->{message} =~ s/\r//g;
- $mail->{message} =~ s/\n/<br>\n/g;
- $myconfig->{signature} =~ s/\n/<br>\n/g;
- $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
+ # if we send html or plain text inline
+ if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
+ $mail->{contenttype} = "text/html";
+ $mail->{message} =~ s/\r//g;
+ $mail->{message} =~ s/\n/<br>\n/g;
+ $myconfig->{signature} =~ s/\n/<br>\n/g;
+ $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
- open(IN, "<", $self->{tmpfile})
- or $self->error($self->cleanup . "$self->{tmpfile} : $!");
- $mail->{message} .= $_ while <IN>;
- close(IN);
+ open(IN, "<", $self->{tmpfile})
+ or $self->error($self->cleanup . "$self->{tmpfile} : $!");
+ $mail->{message} .= $_ while <IN>;
+ close(IN);
- } else {
+ } else {
- if (!$self->{"do_not_attach"}) {
- my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
- $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
- $mail->{attachments} = [{ "filename" => $self->{tmpfile},
- "name" => $attachment_name }];
- }
+ if (!$self->{"do_not_attach"}) {
+ my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
+ $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
+ $mail->{attachments} = [{ "filename" => $self->{tmpfile},
+ "name" => $attachment_name }];
+ }
- $mail->{message} =~ s/\r//g;
- $mail->{message} .= "\n-- \n$myconfig->{signature}";
+ $mail->{message} =~ s/\r//g;
+ $mail->{message} .= "\n-- \n$myconfig->{signature}";
- }
+ }
- my $err = $mail->send();
- $self->error($self->cleanup . "$err") if ($err);
+ my $err = $mail->send();
+ $self->error($self->cleanup . "$err") if ($err);
- } else {
+ } else {
- $self->{OUT} = $out;
- $self->{OUT_MODE} = $out_mode;
+ $self->{OUT} = $out;
+ $self->{OUT_MODE} = $out_mode;
- my $numbytes = (-s $self->{tmpfile});
- open(IN, "<", $self->{tmpfile})
- or $self->error($self->cleanup . "$self->{tmpfile} : $!");
- binmode IN;
+ my $numbytes = (-s $self->{tmpfile});
+ open(IN, "<", $self->{tmpfile})
+ or $self->error($self->cleanup . "$self->{tmpfile} : $!");
+ binmode IN;
- $self->{copies} = 1 unless $self->{media} eq 'printer';
+ $self->{copies} = 1 unless $self->{media} eq 'printer';
- chdir("$self->{cwd}");
- #print(STDERR "Kopien $self->{copies}\n");
- #print(STDERR "OUT $self->{OUT}\n");
- for my $i (1 .. $self->{copies}) {
- if ($self->{OUT}) {
- $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT});
+ chdir("$self->{cwd}");
+ #print(STDERR "Kopien $self->{copies}\n");
+ #print(STDERR "OUT $self->{OUT}\n");
+ for my $i (1 .. $self->{copies}) {
+ if ($self->{OUT}) {
+ $self->{OUT} = $command_formatter->($self->{OUT_MODE}, $self->{OUT});
- open OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
- print OUT $_ while <IN>;
- close OUT;
- seek IN, 0, 0;
+ open OUT, $self->{OUT_MODE}, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
+ print OUT $_ while <IN>;
+ close OUT;
+ seek IN, 0, 0;
- } else {
- $self->{attachment_filename} = ($self->{attachment_filename})
- ? $self->{attachment_filename}
- : $self->generate_attachment_filename();
+ } else {
+ $self->{attachment_filename} = ($self->{attachment_filename})
+ ? $self->{attachment_filename}
+ : $self->generate_attachment_filename();
- # launch application
- print qq|Content-Type: | . $template->get_mime_type() . qq|
+ # launch application
+ print qq|Content-Type: | . $template->get_mime_type() . qq|
Content-Disposition: attachment; filename="$self->{attachment_filename}"
Content-Length: $numbytes
|;
- $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
- }
+ $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
}
-
- close(IN);
}
+ close(IN);
}
$self->cleanup;
return $standard_dbh;
}
+sub set_standard_dbh {
+ my ($self, $dbh) = @_;
+ my $old_dbh = $standard_dbh;
+ $standard_dbh = $dbh;
+
+ return $old_dbh;
+}
+
sub date_closed {
$main::lxdebug->enter_sub();
my ($self, $myconfig, $reference_date) = @_;
- $reference_date = $reference_date ? conv_dateq($reference_date) . '::DATE' : 'current_date';
-
- my $dbh = $self->get_standard_dbh($myconfig);
- my ($payment_id, $duedate);
+ my $terms = $self->{payment_id} ? SL::DB::PaymentTerm->new(id => $self->{payment_id}) ->load
+ : $self->{customer_id} ? SL::DB::Customer ->new(id => $self->{customer_id})->load->payment
+ : $self->{vendor_id} ? SL::DB::Vendor ->new(id => $self->{vendor_id}) ->load->payment
+ : croak("Missing field in \$::form: payment_id, customer_id or vendor_id");
- if($self->{payment_id}) {
- $payment_id = $self->{payment_id};
- } elsif($self->{vendor_id}) {
- my $query = 'SELECT payment_id FROM vendor WHERE id = ?';
- ($payment_id) = selectrow_query($self, $dbh, $query, $self->{vendor_id});
- }
-
- if ($payment_id) {
- my $query = qq|SELECT ${reference_date} + terms_netto FROM payment_terms WHERE id = ?|;
- ($duedate) = selectrow_query($self, $dbh, $query, $payment_id);
- }
+ my $duedate = $terms->calc_date(reference_date => $reference_date)->to_kivitendo;
$main::lxdebug->leave_sub();