Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8743f3cf

Von Tamino Steinert vor 8 Monaten hinzugefügt

  • ID 8743f3cfd51467267369c026b35173192a67d70d
  • Vorgänger b635fe0c

FIX: Beleg-Export -> PDF-Export in Bericht VK-Rechnung, ...

Füge jetzt alle Dateien aus Dokumente zur ZIP-Datei hinzu.
Gebe Fehler direkt aus, wenn Dateien fehlen oder Beleg keine Datei
hat.

Unterschiede anzeigen:

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);
locale/de/all
2476 2476
  'No Company Address given'    => 'Keine Firmenadresse hinterlegt!',
2477 2477
  'No Company Name given'       => 'Kein Firmenname hinterlegt!',
2478 2478
  'No Customer was found matching the search parameters.' => 'Zu dem Suchbegriff wurde kein Endkunde gefunden',
2479
  'No Dokument found for record \'#1\'. Please deselect it or create a document it.' => 'Kein Dokument gefunden für Beleg \'#1\'. Bitte wählen Sie diesen ab oder erstellen Sie ein Dokument für diesen.',
2480
  'No File Management enabled.' => 'Kein Dateimanagement aktiviert.',
2479 2481
  'No GL template was found.'   => 'Keine Dialogbuchungsvorlage gefunden.',
2480 2482
  'No Journal'                  => 'Kein Journal',
2481 2483
  'No Order Number'             => 'Keine Auftragsnummer',
......
2531 2533
  'No file selected, please set one checkbox!' => 'Kein Element selektiert,bitte eine Box anklicken',
2532 2534
  'No file uploaded yet'        => 'Keine Datei hochgeladen',
2533 2535
  'No filename exists!'         => 'Kein Dateiname angegeben',
2534
  'No files backend enabled.'   => 'Dateimanagement nicht aktiviert.',
2535 2536
  'No function blocks have been created yet.' => 'Es wurden noch keine Funktionsblöcke angelegt.',
2536 2537
  'No groups have been created yet.' => 'Es wurden noch keine Gruppen angelegt.',
2537 2538
  'No internal phone extensions have been configured yet.' => 'Es wurden noch keine internen Durchwahlen konfiguriert.',
......
2585 2586
  'No vendor selected or found!' => 'Kein Lieferant ausgewählt oder gefunden!',
2586 2587
  'No vendors to add to purchasebasket' => 'Kein Lieferant',
2587 2588
  'No warehouse has been created yet or the quantity of the bins is not configured yet.' => 'Es wurde noch kein Lager angelegt, bzw. die dazugehörigen Lagerplätze sind noch nicht konfiguriert.',
2588
  'No webdav backend enabled.'  => 'WebDAV nicht aktiviert.',
2589 2589
  'No year given for method year' => 'Für diese Exportmethode wird ein Jahr benötigt',
2590 2590
  'No.'                         => 'Position',
2591 2591
  'No/individual shipping address' => 'Keine/individuelle Lieferadresse',
......
2765 2765
  'PDF export'                  => 'PDF-Export',
2766 2766
  'PDF export -- options'       => 'PDF-Export -- Optionen',
2767 2767
  'PDF export with attachments' => 'Als PDF mit Anhängen exportieren',
2768
  'PDF-Export'                  => 'PDF-Export',
2768 2769
  'PLZ Grosskunden'             => 'PLZ Grosskunden',
2769 2770
  'POSTED'                      => 'Gebucht',
2770 2771
  'POSTED AS NEW'               => 'Als neu gebucht',
......
3220 3221
  'Record templates'            => 'Belegvorlagen',
3221 3222
  'Record type to create'       => 'Anzulegender Belegtyp',
3222 3223
  'Record\'s files'             => 'Belegdateien',
3223
  'Record-Export'               => 'Beleg-Export',
3224 3224
  'Recorded Tax'                => 'Gespeicherte Steuern',
3225 3225
  'Recorded taxkey'             => 'Gespeicherter Steuerschlüssel',
3226 3226
  'Records'                     => 'Belege',
......
4815 4815
  'We need a valid to date'     => 'Es wird ein gültiges bis Datum erwartet',
4816 4816
  'Web shops'                   => 'Webshops',
4817 4817
  'WebDAV'                      => 'WebDAV',
4818
  'WebDAV is not enabled.'      => 'WebDAV ist nicht aktiviert.',
4818 4819
  'WebDAV link'                 => 'WebDAV-Link',
4819 4820
  'WebDAV save documents'       => 'Belege in WebDAV-Ablage speichern',
4820 4821
  'WebDAV sync extern'          => 'WebDAV Synchronisation extern',
......
5114 5115
  'no shipping address'         => 'keine Lieferadresse',
5115 5116
  'no skonto_chart configured for taxkey #1 : #2 : #3' => 'Kein Skontokonto für Steuerschlüssel #1 : #2 : #3',
5116 5117
  'no tax_id in acc_trans'      => 'Keine tax_id in acc_trans',
5117
  'no_file_found.txt'           => 'keine_datei_gefunden.txt',
5118 5118
  'not a valid DTVF file, expected field header start with \'Umsatz; (..) ;Konto;Gegenkonto\'' => 'Keine gültige DTVF-Datei, die erwartete Kopfzeile startet mit \'Umsatz; (..) ;Konto;Gegenkonto\'',
5119 5119
  'not a valid DTVF file, expected first field in A1 \'DTVF\'' => 'Keine gültige DTVF-Datei, der erwarte Feldwert in A1 ist \'DTVF\'',
5120 5120
  'not configured'              => 'nicht konfiguriert',
locale/en/all
2475 2475
  'No Company Address given'    => '',
2476 2476
  'No Company Name given'       => '',
2477 2477
  'No Customer was found matching the search parameters.' => '',
2478
  'No Dokument found for record \'#1\'. Please deselect it or create a document it.' => '',
2479
  'No File Management enabled.' => '',
2478 2480
  'No GL template was found.'   => '',
2479 2481
  'No Journal'                  => '',
2480 2482
  'No Order Number'             => '',
......
2530 2532
  'No file selected, please set one checkbox!' => '',
2531 2533
  'No file uploaded yet'        => '',
2532 2534
  'No filename exists!'         => '',
2533
  'No files backend enabled.'   => '',
2534 2535
  'No function blocks have been created yet.' => '',
2535 2536
  'No groups have been created yet.' => '',
2536 2537
  'No internal phone extensions have been configured yet.' => '',
......
2584 2585
  'No vendor selected or found!' => '',
2585 2586
  'No vendors to add to purchasebasket' => '',
2586 2587
  'No warehouse has been created yet or the quantity of the bins is not configured yet.' => '',
2587
  'No webdav backend enabled.'  => '',
2588 2588
  'No year given for method year' => '',
2589 2589
  'No.'                         => '',
2590 2590
  'No/individual shipping address' => '',
......
2764 2764
  'PDF export'                  => '',
2765 2765
  'PDF export -- options'       => '',
2766 2766
  'PDF export with attachments' => '',
2767
  'PDF-Export'                  => '',
2767 2768
  'PLZ Grosskunden'             => '',
2768 2769
  'POSTED'                      => '',
2769 2770
  'POSTED AS NEW'               => '',
......
3219 3220
  'Record templates'            => '',
3220 3221
  'Record type to create'       => '',
3221 3222
  'Record\'s files'             => '',
3222
  'Record-Export'               => '',
3223 3223
  'Recorded Tax'                => '',
3224 3224
  'Recorded taxkey'             => '',
3225 3225
  'Records'                     => '',
......
4813 4813
  'We need a valid to date'     => '',
4814 4814
  'Web shops'                   => '',
4815 4815
  'WebDAV'                      => '',
4816
  'WebDAV is not enabled.'      => '',
4816 4817
  'WebDAV link'                 => '',
4817 4818
  'WebDAV save documents'       => '',
4818 4819
  'WebDAV sync extern'          => '',
......
5112 5113
  'no shipping address'         => '',
5113 5114
  'no skonto_chart configured for taxkey #1 : #2 : #3' => '',
5114 5115
  'no tax_id in acc_trans'      => '',
5115
  'no_file_found.txt'           => '',
5116 5116
  'not a valid DTVF file, expected field header start with \'Umsatz; (..) ;Konto;Gegenkonto\'' => '',
5117 5117
  'not a valid DTVF file, expected first field in A1 \'DTVF\'' => '',
5118 5118
  'not configured'              => '',

Auch abrufbar als: Unified diff