Revision 2768714b
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
bin/mozilla/ar.pl | ||
---|---|---|
35 | 35 |
use POSIX qw(strftime); |
36 | 36 |
use List::Util qw(sum first max); |
37 | 37 |
use List::UtilsBy qw(sort_by); |
38 |
use Archive::Zip; |
|
38 | 39 |
|
39 | 40 |
use SL::AR; |
40 | 41 |
use SL::Controller::Base; |
... | ... | |
48 | 49 |
use SL::DB::Default; |
49 | 50 |
use SL::DB::Employee; |
50 | 51 |
use SL::DB::Invoice; |
52 |
use SL::DB::Manager::Invoice; |
|
51 | 53 |
use SL::DB::InvoiceItem; |
52 | 54 |
use SL::DB::RecordTemplate; |
53 | 55 |
use SL::DB::Tax; |
... | ... | |
58 | 60 |
use SL::Presenter::Chart; |
59 | 61 |
use SL::Presenter::ItemsList; |
60 | 62 |
use SL::ReportGenerator; |
63 |
use SL::File::Object; |
|
64 |
use SL::DB::Manager::File; |
|
65 |
use SL::File::Backend::Filesystem; |
|
66 |
use SL::Webdav; |
|
67 |
use SL::File::Backend::Webdav; |
|
61 | 68 |
|
62 | 69 |
require "bin/mozilla/common.pl"; |
63 | 70 |
require "bin/mozilla/reportgenerator.pl"; |
... | ... | |
937 | 944 |
my %params = @_; |
938 | 945 |
my $may_edit_create = $::auth->assert('invoice_edit', 1); |
939 | 946 |
|
947 |
my $webdav_enabled = SL::File::Backend::Webdav->enabled(); |
|
948 |
my $files_enabled = SL::File::Backend::Filesystem->enabled(); |
|
949 |
|
|
940 | 950 |
for my $bar ($::request->layout->get('actionbar')) { |
941 | 951 |
$bar->add( |
942 | 952 |
action => [ |
... | ... | |
946 | 956 |
: !$params{num_rows} ? $::locale->text('The report doesn\'t contain entries.') |
947 | 957 |
: undef, |
948 | 958 |
], |
949 |
|
|
959 |
combobox => [ |
|
960 |
action => [ $::locale->text('Record-Export') ], |
|
961 |
action => [ |
|
962 |
t8('WebDAV'), |
|
963 |
submit => [ '#report_form', { action => 'webdav_pdf_export' } ], |
|
964 |
checks => [ ['kivi.check_if_entries_selected', '[name="id[]"]'] ], |
|
965 |
disabled => !$webdav_enabled ? t8('No webdav backend enabled.') |
|
966 |
: undef, |
|
967 |
], |
|
968 |
action => [ |
|
969 |
t8('Files'), |
|
970 |
submit => [ '#report_form', { action => 'files_pdf_export' } ], |
|
971 |
checks => [ ['kivi.check_if_entries_selected', '[name="id[]"]'] ], |
|
972 |
disabled => !$files_enabled ? t8('No files backend enabled.') |
|
973 |
: undef, |
|
974 |
], |
|
975 |
], |
|
950 | 976 |
combobox => [ |
951 | 977 |
action => [ $::locale->text('Create new') ], |
952 | 978 |
action => [ |
... | ... | |
1504 | 1530 |
$::request->layout->add_javascripts('kivi.Validator.js'); |
1505 | 1531 |
} |
1506 | 1532 |
|
1533 |
sub webdav_pdf_export { |
|
1534 |
$main::lxdebug->enter_sub(); |
|
1535 |
|
|
1536 |
# TODO(Tamino): rights? |
|
1537 |
$::auth->assert('ar_transactions'); |
|
1538 |
$::auth->assert('invoice_edit'); |
|
1539 |
|
|
1540 |
my $form = $main::form; |
|
1541 |
my $ids = $form->{id}; |
|
1542 |
|
|
1543 |
my $invoices = SL::DB::Manager::Invoice->get_all(where => [ id => $ids ]); |
|
1544 |
|
|
1545 |
my %file_name_to_path = (); |
|
1546 |
my $no_files = ""; |
|
1547 |
foreach my $invoice (@{$invoices}) { |
|
1548 |
if ($invoice->type eq '') { |
|
1549 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1550 |
$main::lxdebug->dump(0, "TST: no_files loop", $no_files); |
|
1551 |
next; |
|
1552 |
} |
|
1553 |
my $webdav = SL::Webdav->new( |
|
1554 |
type => $invoice->type, |
|
1555 |
number => $invoice->record_number, |
|
1556 |
); |
|
1557 |
my @latest_object = $webdav->get_all_latest(); |
|
1558 |
if (scalar @latest_object) { |
|
1559 |
my $file_name = $latest_object[0]->basename . "." . $latest_object[0]->extension; |
|
1560 |
$file_name_to_path{$file_name} = $latest_object[0]->full_filedescriptor(); |
|
1561 |
} else { |
|
1562 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1563 |
} |
|
1564 |
} |
|
1565 |
|
|
1566 |
_create_and_send_zip(\%file_name_to_path, $no_files); |
|
1567 |
|
|
1568 |
$main::lxdebug->leave_sub(); |
|
1569 |
} |
|
1570 |
|
|
1571 |
sub files_pdf_export { |
|
1572 |
$main::lxdebug->enter_sub(); |
|
1573 |
|
|
1574 |
# TODO(Tamino): rights? |
|
1575 |
$::auth->assert('ar_transactions'); |
|
1576 |
$::auth->assert('invoice_edit'); |
|
1577 |
|
|
1578 |
my $form = $main::form; |
|
1579 |
my $ids = $form->{id}; |
|
1580 |
|
|
1581 |
my $invoices = SL::DB::Manager::Invoice->get_all(where => [ id => $ids ]); |
|
1582 |
|
|
1583 |
my %file_name_to_path = (); |
|
1584 |
my $no_files = ""; |
|
1585 |
foreach my $invoice (@{$invoices}) { |
|
1586 |
my $file_entry = SL::DB::Manager::File->get_first( |
|
1587 |
query => [ |
|
1588 |
object_type => $invoice->type, |
|
1589 |
object_id => $invoice->id, |
|
1590 |
], |
|
1591 |
); |
|
1592 |
if ($file_entry) { |
|
1593 |
my $file = SL::File::Object->new( |
|
1594 |
db_file => $file_entry, |
|
1595 |
id => $file_entry->id, |
|
1596 |
loaded => 1, |
|
1597 |
); |
|
1598 |
$file_name_to_path{$file->file_name()} = $file->get_file(); |
|
1599 |
} else { |
|
1600 |
$no_files .= $invoice->displayable_name() . "\n"; |
|
1601 |
} |
|
1602 |
} |
|
1603 |
|
|
1604 |
|
|
1605 |
_create_and_send_zip(\%file_name_to_path, $no_files); |
|
1606 |
|
|
1607 |
$main::lxdebug->leave_sub(); |
|
1608 |
} |
|
1609 |
|
|
1610 |
sub _create_and_send_zip { |
|
1611 |
my ($file_name_to_path, $no_files) = @_; |
|
1612 |
$main::lxdebug->enter_sub(); |
|
1613 |
|
|
1614 |
my ($fh, $zipfile) = File::Temp::tempfile(); |
|
1615 |
my $zip = Archive::Zip->new(); |
|
1616 |
foreach my $name (keys %{$file_name_to_path}) { |
|
1617 |
$zip->addFile($file_name_to_path->{$name}, $name); |
|
1618 |
} |
|
1619 |
if ($no_files ne '') { |
|
1620 |
$zip->addString($no_files, t8('no_file_found.txt')); |
|
1621 |
} |
|
1622 |
$zip->writeToFileHandle($fh) == Archive::Zip::AZ_OK() or die 'error writing zip file'; |
|
1623 |
close($fh); |
|
1624 |
|
|
1625 |
my $controller = SL::Controller::Base->new; |
|
1626 |
|
|
1627 |
$controller->send_file($zipfile, name => t8('pdf_records.zip'), unlink => 1); |
|
1628 |
|
|
1629 |
$main::lxdebug->leave_sub(); |
|
1630 |
} |
|
1631 |
|
|
1632 |
|
|
1507 | 1633 |
1; |
Auch abrufbar als: Unified diff
Beleg-Pdf aus Rechnungs/Gutschriften-Bericht herunterladen