1 #=====================================================================
 
   6 #   Email: p.reetz@linet-services.de
 
   7 #     Web: http://www.lx-office.org
 
  10 # This program is free software; you can redistribute it and/or modify
 
  11 # it under the terms of the GNU General Public License as published by
 
  12 # the Free Software Foundation; either version 2 of the License, or
 
  13 # (at your option) any later version.
 
  15 # This program is distributed in the hope that it will be useful,
 
  16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  18 # GNU General Public License for more details.
 
  19 # You should have received a copy of the GNU General Public License
 
  20 # along with this program; if not, write to the Free Software
 
  21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  22 #======================================================================
 
  26 #======================================================================
 
  28 use POSIX qw(strftime getcwd);
 
  29 use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
 
  40 require "bin/mozilla/common.pl";
 
  42 sub continue { call_sub($main::form->{"nextsub"}); }
 
  45   $main::lxdebug->enter_sub();
 
  47   my $form     = $main::form;
 
  48   my %myconfig = %main::myconfig;
 
  49   my $locale   = $main::locale;
 
  51   $main::auth->assert('datev_export');
 
  53   $form->{title} = $locale->text("DATEX - Export Assistent");
 
  55   DATEV->get_datev_stamm(\%myconfig, \%$form);
 
  61 <form method=post action=$form->{script}>
 
  66     <th class=listtop>$form->{title}</th>
 
  69     <th align=left>| . $locale->text("DATEV Angaben") . qq|</th>
 
  76           <td align=left nowrap>| . $locale->text("Beraternummer") . qq|</td>
 
  77           <td><input name=beraternr size=10 maxlength=7 value="$form->{beraternr}"></td>
 
  79           <td align=left nowrap>| . $locale->text("DFV-Kennzeichen") . qq|</td>
 
  80           <td><input name=dfvkz size=5 maxlength=2 value="$form->{dfvkz}"></td>
 
  83           <td align=left nowrap>| . $locale->text("Beratername") . qq|</td>
 
  84           <td><input name=beratername size=10 maxlength=9 value="$form->{beratername}"></td>
 
  86           <td align=left nowrap>| . $locale->text("Password") . qq|</td>
 
  87           <td><input name=passwort size=5 maxlength=4 value="$form->{passwort}"></td>
 
  90           <td align=left nowrap>| . $locale->text("Mandantennummer") . qq|</td>
 
  91           <td><input name=mandantennr size=10 maxlength=5 value="$form->{mandantennr}"></td>
 
  93           <td align=left nowrap>| . $locale->text("Medium Number") . qq|</td>
 
  94           <td><input name=datentraegernr size=5 maxlength=3 value="$form->{datentraegernr}"></td>
 
  97           | . # OBE-Export noch nicht implementiert! <td><input checked name=kne type=checkbox class=checkbox value=1> | . $locale->text("Kontonummernerweiterung (KNE)") . qq|</td>
 
  98     qq|<td><input type="hidden" name="kne" value="1"></td>
 
 101           <td align=left nowrap>| . $locale->text("Abrechnungsnummer") . qq|</td>
 
 102           <td><input name=abrechnungsnr size=5 maxlength=3 value="$form->{abrechnungsnr}"></td>
 
 106           <td><input name=exporttype type=radio class=radio value=0 checked> |
 
 107     . $locale->text("Export Buchungsdaten") . qq|</td>
 
 110           <td><input name=exporttype type=radio class=radio value=1> |
 
 111     . $locale->text("Export Stammdaten") . qq|</td>
 
 118     <td><hr size=3 noshade></td>
 
 122 <input type=hidden name=nextsub value=export2>
 
 125 <input type=submit class=submit name=action value="|
 
 126     . $locale->text('Continue') . qq|">
 
 132   $main::lxdebug->leave_sub();
 
 136   $main::lxdebug->enter_sub();
 
 138   my $form     = $main::form;
 
 140   $main::auth->assert('datev_export');
 
 142   if ($form->{exporttype} == 0) {
 
 143     &export_bewegungsdaten();
 
 145     &export_stammdaten();
 
 147   $main::lxdebug->leave_sub();
 
 150 sub export_bewegungsdaten {
 
 151   $main::lxdebug->enter_sub();
 
 153   my $form     = $main::form;
 
 154   my %myconfig = %main::myconfig;
 
 155   my $locale   = $main::locale;
 
 157   $main::auth->assert('datev_export');
 
 159   $form->{title} = $locale->text("DATEX - Export Assistent");
 
 161   $form->{allemonate} =
 
 163     . $locale->text('January')
 
 166     . $locale->text('February') . qq|</option>
 
 168     . $locale->text('March') . qq|</option>
 
 170     . $locale->text('April') . qq|</option>
 
 172     . $locale->text('May') . qq|</option>
 
 174     . $locale->text('June') . qq|</option>
 
 176     . $locale->text('July') . qq|</option>
 
 178     . $locale->text('August') . qq|</option>
 
 180     . $locale->text('September') . qq|</option>
 
 182     . $locale->text('October') . qq|</option>
 
 184     . $locale->text('November') . qq|</option>
 
 186     . $locale->text('December') . qq|</option>|;
 
 188   $form->{allequartale} =
 
 189       qq|<option selected value=1>|
 
 192                          <option value=2>| . $locale->text('II') . qq|</option>
 
 194     . $locale->text('III') . qq|</option>
 
 196     . $locale->text('IV') . qq|</option>|;
 
 197   $form->{"jsscript"} = 1;
 
 203 <form method=post action=$form->{script}>
 
 208     <th class=listtop>$form->{title}</th>
 
 211     <th align=left>| . $locale->text("Zeitraum") . qq|</th>
 
 218           <td align=left><input checked name=zeitraum class=radio type=radio value=monat> </td><td align=left>|
 
 219     . $locale->text('Monat') . qq|</td>
 
 222           <td align=left><select name=monat>$form->{allemonate}</select></td>
 
 225           <td align=left><input name=zeitraum class=radio type=radio value=quartal> </td><td align=left>|
 
 226     . $locale->text('Quartal') . qq|</td>
 
 229           <td align=left><select name=quartal>$form->{allequartale}</select></td>
 
 232           <td align=left><input name=zeitraum class=radio type=radio value=zeit> </td><td align=left>|
 
 233     . $locale->text('Datum von') . qq|</td>
 
 234           <td align=left><input id=transdatefrom name=transdatefrom size=10>
 
 235             <input type="button" name="transdatefrom" id="trigger_transdatefrom" value="?"></td>
 
 236           <td align=left>| . $locale->text('bis') . qq|</td>
 
 237           <td align=left><input id=transdateto name=transdateto size=10>
 
 238             <input type="button" name="transdateto" id="trigger_transdateto" value="?"></td>
 
 244     <td><hr size=3 noshade></td>
 
 248 | . $form->write_trigger(\%myconfig, 2,
 
 249                          "transdatefrom", "BL", "trigger_transdatefrom",
 
 250                          "transdateto", "BL", "trigger_transdateto") . qq|
 
 252 <input type=hidden name=beraternr value="$form->{beraternr}">
 
 253 <input type=hidden name=dfvkz value="$form->{dfvkz}">
 
 254 <input type=hidden name=beratername value="$form->{beratername}">
 
 255 <input type=hidden name=passwort value="$form->{passwort}">
 
 256 <input type=hidden name=mandantennr value="$form->{mandantennr}">
 
 257 <input type=hidden name=datentraegernr value="$form->{datentraegernr}">
 
 258 <input type=hidden name=kne value="$form->{kne}">
 
 259 <input type=hidden name=abrechnungsnr value="$form->{abrechnungsnr}">
 
 261 <input type=hidden name=exporttype value="$form->{exporttype}">
 
 263 <input type=hidden name=nextsub value=export3>
 
 266 <input type=submit class=submit name=action value="|
 
 267     . $locale->text('Continue') . qq|">
 
 274   $main::lxdebug->leave_sub();
 
 277 sub export_stammdaten {
 
 278   $main::lxdebug->enter_sub();
 
 280   my $form     = $main::form;
 
 281   my $locale   = $main::locale;
 
 283   $main::auth->assert('datev_export');
 
 285   $form->{title} = $locale->text("DATEX - Export Assistent");
 
 292 <form method=post action=$form->{script}>
 
 295     <th class=listtop>$form->{title}</th>
 
 298     <th align=left>| . $locale->text("Konten") . qq|</th>
 
 305           <td align=left>| . $locale->text('Von Konto: ') . qq|</td>
 
 306           <td align=left><input name=accnofrom size=8 maxlength=8></td>
 
 309           <td align=left>| . $locale->text('Bis Konto: ') . qq|</td>
 
 310           <td align=left><input name=accnoto size=8 maxlength=8></td>
 
 316     <td><hr size=3 noshade></td>
 
 319 <input type=hidden name=beraternr value="$form->{beraternr}">
 
 320 <input type=hidden name=dfvkz value="$form->{dfvkz}">
 
 321 <input type=hidden name=beratername value="$form->{beratername}">
 
 322 <input type=hidden name=passwort value="$form->{passwort}">
 
 323 <input type=hidden name=mandantennr value="$form->{mandantennr}">
 
 324 <input type=hidden name=datentraegernr value="$form->{datentraegernr}">
 
 325 <input type=hidden name=kne value="$form->{kne}">
 
 326 <input type=hidden name=abrechnungsnr value="$form->{abrechnungsnr}">
 
 328 <input type=hidden name=exporttype value="$form->{exporttype}">
 
 330 <input type=hidden name=nextsub value=export3>
 
 333 <input type=submit class=submit name=action value="|
 
 334     . $locale->text('Continue') . qq|">
 
 341   $main::lxdebug->leave_sub();
 
 345   $main::lxdebug->enter_sub();
 
 347   my $form     = $main::form;
 
 348   my %myconfig = %main::myconfig;
 
 349   my $locale   = $main::locale;
 
 351   $main::auth->assert('datev_export');
 
 353   DATEV::clean_temporary_directories();
 
 355   DATEV->save_datev_stamm(\%myconfig, \%$form);
 
 357   my $link = "datev.pl?action=download&download_token=";
 
 360     my $result = DATEV->kne_export(\%myconfig, \%$form);
 
 361     if ($result && @{ $result->{filenames} }) {
 
 362       $link .= Q($result->{download_token});
 
 364       print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|);
 
 366       print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} };
 
 369       $form->error("KNE-Export schlug fehl.");
 
 372     # OBE-Export nicht implementiert.
 
 374     # my @filenames = DATEV->obe_export(\%myconfig, \%$form);
 
 376     #   print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
 
 377     #   $link .= "&filenames=" . $form->escape(join(":", @filenames));
 
 378     #   print(qq|<br><a href="$link">Download</a>|);
 
 380     #   $form->error("OBE-Export schlug fehl.");
 
 384   print("</body></html>");
 
 386   $main::lxdebug->leave_sub();
 
 390   $main::lxdebug->enter_sub();
 
 392   my $form     = $main::form;
 
 393   my $locale   = $main::locale;
 
 395   $main::auth->assert('datev_export');
 
 397   my $tmp_name = Common->tmpname();
 
 398   my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
 
 402   my $path = DATEV::get_path_for_download_token($form->{download_token});
 
 404     $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
 
 407   chdir($path) || die("chdir $path");
 
 409   my @filenames = glob "*";
 
 413     DATEV::clean_temporary_directories();
 
 414     $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
 
 417   my $zip = Archive::Zip->new();
 
 418   map { $zip->addFile($_); } @filenames;
 
 419   $zip->writeToFileNamed($tmp_name);
 
 423   open(IN, $tmp_name) || die("open $tmp_name");
 
 424   $::locale->with_raw_io(\*STDOUT, sub {
 
 425     print("Content-Type: application/zip\n");
 
 426     print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n");
 
 435   DATEV::clean_temporary_directories();
 
 437   $main::lxdebug->leave_sub();