Revision f5b81396
Von Tamino Steinert vor 2 Monaten hinzugefügt
bin/mozilla/ar.pl | ||
---|---|---|
36 | 36 |
use List::Util qw(sum first max); |
37 | 37 |
use List::UtilsBy qw(sort_by); |
38 | 38 |
use Archive::Zip; |
39 |
use Params::Validate qw(:all); |
|
39 | 40 |
|
40 | 41 |
use SL::AR; |
41 | 42 |
use SL::Controller::Base; |
... | ... | |
1028 | 1029 |
: undef, |
1029 | 1030 |
], |
1030 | 1031 |
combobox => [ |
1031 |
action => [ $::locale->text('Record-Export') ],
|
|
1032 |
action => [ $::locale->text('PDF-Export') ],
|
|
1032 | 1033 |
action => [ |
1033 | 1034 |
t8('WebDAV'), |
1034 | 1035 |
submit => [ '#report_form', { action => 'webdav_pdf_export' } ], |
1035 | 1036 |
checks => [ ['kivi.check_if_entries_selected', '[name="id[]"]'] ], |
1036 |
disabled => !$webdav_enabled ? t8('No webdav backend enabled.')
|
|
1037 |
disabled => !$webdav_enabled ? t8('WebDAV is not enabled.')
|
|
1037 | 1038 |
: undef, |
1038 | 1039 |
], |
1039 | 1040 |
action => [ |
1040 |
t8('Files'),
|
|
1041 |
t8('Documents'),
|
|
1041 | 1042 |
submit => [ '#report_form', { action => 'files_pdf_export' } ], |
1042 | 1043 |
checks => [ ['kivi.check_if_entries_selected', '[name="id[]"]'] ], |
1043 |
disabled => !$files_enabled ? t8('No files backend enabled.')
|
|
1044 |
disabled => !$files_enabled ? t8('No File Management enabled.')
|
|
1044 | 1045 |
: undef, |
1045 | 1046 |
], |
1046 | 1047 |
], |
... | ... | |
1686 | 1687 |
|
1687 | 1688 |
my $invoices = SL::DB::Manager::Invoice->get_all(where => [ id => $ids ]); |
1688 | 1689 |
|
1689 |
my %file_name_to_path = ();
|
|
1690 |
my $no_files = "";
|
|
1690 |
my @file_names_and_file_paths;
|
|
1691 |
my @errors;
|
|
1691 | 1692 |
foreach my $invoice (@{$invoices}) { |
1692 |
if ($invoice->type eq '') { |
|
1693 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1694 |
next; |
|
1695 |
} |
|
1693 |
my $record_type = $invoice->record_type; |
|
1694 |
$record_type = 'general_ledger' if $record_type eq 'ar_transaction'; |
|
1695 |
$record_type = 'invoice' if $record_type eq 'invoice_storno'; |
|
1696 | 1696 |
my $webdav = SL::Webdav->new( |
1697 |
type => $invoice->type,
|
|
1697 |
type => $record_type,
|
|
1698 | 1698 |
number => $invoice->record_number, |
1699 | 1699 |
); |
1700 | 1700 |
my @latest_object = $webdav->get_all_latest(); |
1701 |
if (scalar @latest_object) { |
|
1702 |
my $file_name = $latest_object[0]->basename . "." . $latest_object[0]->extension; |
|
1703 |
$file_name_to_path{$file_name} = $latest_object[0]->full_filedescriptor(); |
|
1704 |
} else { |
|
1705 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1701 |
unless (scalar @latest_object) { |
|
1702 |
push @errors, t8( |
|
1703 |
"No Dokument found for record '#1'. Please deselect it or create a document it.", |
|
1704 |
$invoice->displayable_name() |
|
1705 |
); |
|
1706 |
next; |
|
1707 |
} |
|
1708 |
push @file_names_and_file_paths, { |
|
1709 |
file_name => $latest_object[0]->basename . "." . $latest_object[0]->extension, |
|
1710 |
file_path => $latest_object[0]->full_filedescriptor(), |
|
1706 | 1711 |
} |
1707 | 1712 |
} |
1708 | 1713 |
|
1709 |
_create_and_send_zip(\%file_name_to_path, $no_files); |
|
1714 |
if (scalar @errors) { |
|
1715 |
die join("\n", @errors); |
|
1716 |
} |
|
1717 |
_create_and_send_zip(\@file_names_and_file_paths); |
|
1710 | 1718 |
|
1711 | 1719 |
$main::lxdebug->leave_sub(); |
1712 | 1720 |
} |
... | ... | |
1721 | 1729 |
|
1722 | 1730 |
my $invoices = SL::DB::Manager::Invoice->get_all(where => [ id => $ids ]); |
1723 | 1731 |
|
1724 |
my %file_name_to_path = ();
|
|
1725 |
my $no_files = "";
|
|
1732 |
my @file_names_and_file_paths;
|
|
1733 |
my @errors;
|
|
1726 | 1734 |
foreach my $invoice (@{$invoices}) { |
1727 |
my $file_entry = SL::DB::Manager::File->get_first( |
|
1728 |
query => [ |
|
1729 |
object_type => $invoice->type, |
|
1735 |
my $record_type = $invoice->record_type; |
|
1736 |
$record_type = 'invoice' if $record_type eq 'ar_transaction'; |
|
1737 |
$record_type = 'invoice' if $record_type eq 'invoice_storno'; |
|
1738 |
my @file_entries = @{SL::DB::Manager::File->get_all( |
|
1739 |
where => [ |
|
1740 |
object_type => $record_type, |
|
1730 | 1741 |
object_id => $invoice->id, |
1742 |
file_type => 'document', |
|
1743 |
source => 'created', |
|
1731 | 1744 |
], |
1732 |
); |
|
1733 |
if ($file_entry) { |
|
1745 |
)}; |
|
1746 |
|
|
1747 |
unless (scalar @file_entries) { |
|
1748 |
push @errors, t8( |
|
1749 |
"No Dokument found for record '#1'. Please deselect it or create a document it.", |
|
1750 |
$invoice->displayable_name() |
|
1751 |
); |
|
1752 |
next; |
|
1753 |
} |
|
1754 |
foreach my $file_entry (@file_entries) { |
|
1734 | 1755 |
my $file = SL::File::Object->new( |
1735 | 1756 |
db_file => $file_entry, |
1736 | 1757 |
id => $file_entry->id, |
1737 | 1758 |
loaded => 1, |
1738 | 1759 |
); |
1739 |
$file_name_to_path{$file->file_name()} = $file->get_file(); |
|
1740 |
} else { |
|
1741 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1760 |
eval { |
|
1761 |
push @file_names_and_file_paths, { |
|
1762 |
file_name => $file->file_name, |
|
1763 |
file_path => $file->get_file(), |
|
1764 |
}; |
|
1765 |
} or do { |
|
1766 |
push @errors, $@, |
|
1767 |
}; |
|
1742 | 1768 |
} |
1743 | 1769 |
} |
1744 | 1770 |
|
1745 |
|
|
1746 |
_create_and_send_zip(\%file_name_to_path, $no_files); |
|
1771 |
if (scalar @errors) { |
|
1772 |
die join("\n", @errors); |
|
1773 |
} |
|
1774 |
_create_and_send_zip(\@file_names_and_file_paths); |
|
1747 | 1775 |
|
1748 | 1776 |
$main::lxdebug->leave_sub(); |
1749 | 1777 |
} |
1750 | 1778 |
|
1751 | 1779 |
sub _create_and_send_zip { |
1752 |
my ($file_name_to_path, $no_files) = @_; |
|
1753 | 1780 |
$main::lxdebug->enter_sub(); |
1781 |
my ($file_names_and_file_paths) = validate_pos(@_, { |
|
1782 |
type => ARRAYREF, |
|
1783 |
callbacks => { |
|
1784 |
"has 'file_name' and 'file_path'" => sub { |
|
1785 |
foreach my $file_entry (@{$_[0]}) { |
|
1786 |
return 0 unless defined $file_entry->{file_name} |
|
1787 |
&& defined $file_entry->{file_path}; |
|
1788 |
} |
|
1789 |
return 1; |
|
1790 |
} |
|
1791 |
} |
|
1792 |
}); |
|
1754 | 1793 |
|
1755 | 1794 |
my ($fh, $zipfile) = File::Temp::tempfile(); |
1756 | 1795 |
my $zip = Archive::Zip->new(); |
1757 |
foreach my $name (keys %{$file_name_to_path}) { |
|
1758 |
$zip->addFile($file_name_to_path->{$name}, $name); |
|
1759 |
} |
|
1760 |
if ($no_files ne '') { |
|
1761 |
$zip->addString($no_files, t8('no_file_found.txt')); |
|
1796 |
foreach my $file (@{$file_names_and_file_paths}) { |
|
1797 |
$zip->addFile($file->{file_path}, $file->{file_name}); |
|
1762 | 1798 |
} |
1763 | 1799 |
$zip->writeToFileHandle($fh) == Archive::Zip::AZ_OK() or die 'error writing zip file'; |
1764 | 1800 |
close($fh); |
Auch abrufbar als: Unified diff
FIX: Beleg-Export -> PDF-Export in Bericht VK-Rechnung, ...