Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 05f4e6eb

Von Bernd Bleßmann vor fast 4 Jahren hinzugefügt

  • ID 05f4e6ebf1257a454290c04e5e7ede90eca0e465
  • Vorgänger 4f0087b8
  • Nachfolger 4e36326b

Mahnungen: DMS/WebDAV: erzeugte Dokumente nach Mahnlauf ablegen.

Und zwar außerhalb der Transaktion und nur wenn diese erfolgreich war,
sonst können bei eine abgebrochenen Transaktion abgelegte Dokumente
vorhanden sein, ohne das eine Mahnung oder Mahnrechnung in der DB existiert.

Unterschiede anzeigen:

SL/DN.pm
317 317
  my ($self, $myconfig, $form, $rows) = @_;
318 318
  $main::lxdebug->enter_sub();
319 319

  
320
  $form->{DUNNING_PDFS_STORAGE} = [];
321

  
320 322
  my $rc = SL::DB->client->with_transaction(\&_save_dunning, $self, $myconfig, $form, $rows);
321 323

  
324
  # Save PDFs in filemanagement and webdav after transation succeeded,
325
  # because otherwise files in the storage may exists if the transaction
326
  # failed. Ignore all errros.
327
  # Todo: Maybe catch errros and display them as warnings or non fatal errors in the status.
328
  if (!$error && $form->{DUNNING_PDFS_STORAGE} && scalar @{ $form->{DUNNING_PDFS_STORAGE} }) {
329
    _store_pdf_to_webdav_and_filemanagement($_->{dunning_id}, $_->{path}, $_->{name}) for @{ $form->{DUNNING_PDFS_STORAGE} };
330
  }
331

  
322 332
  if (!$rc) {
323 333
    die SL::DB->client->error
324 334
  }
......
998 1008

  
999 1009
  delete $form->{tmpfile};
1000 1010

  
1001
  push @{ $form->{DUNNING_PDFS} }, $filename;
1002
  push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$filename",
1003
                                           'name'     => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" };
1011
  push @{ $form->{DUNNING_PDFS} }        , $filename;
1012
  push @{ $form->{DUNNING_PDFS_EMAIL} }  , { 'path'       => "${spool}/$filename",
1013
                                             'name'       => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" };
1014
  push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1015
                                             'path'       => "${spool}/$filename",
1016
                                             'name'       => $form->get_formname_translation('dunning') . "_${dunning_id}.pdf" };
1004 1017

  
1005 1018
  my $employee_id = ($::instance_conf->get_dunning_creator eq 'invoice_employee') ?
1006 1019
                      $form->{employee_id}                                        :
......
1019 1032
  # this generates the file in the spool directory
1020 1033
  $form->parse_template($myconfig);
1021 1034

  
1022
  # save dunning pdf in filemanagement/webdav
1023
  if ($::instance_conf->get_doc_storage) {
1024
    SL::File->save(
1025
      object_id   => $dunning_id,
1026
      object_type => 'dunning',
1027
      mime_type   => 'application/pdf',
1028
      source      => 'created',
1029
      file_type   => 'document',
1030
      file_name   => $form->{attachment_filename},
1031
      file_path   => "${spool}/$filename",
1032
    );
1033
  }
1034
  if ($::instance_conf->get_webdav_documents) {
1035
    my $webdav = SL::Webdav->new(
1036
      type     => 'dunning',
1037
      number   => $dunning_id,
1038
    );
1039
    my $webdav_file = SL::Webdav::File->new(
1040
      webdav   => $webdav,
1041
      filename => $form->{attachment_filename},
1042
    );
1043
    $webdav_file->store(file => "${spool}/$filename");
1044
  }
1045

  
1046 1035
  $main::lxdebug->leave_sub();
1047 1036
}
1048 1037

  
......
1140 1129

  
1141 1130
  restore_form($saved_form);
1142 1131

  
1143
  push @{ $form->{DUNNING_PDFS} }, $filename;
1144
  push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$filename",
1145
                                           'name' => $attachment_filename };
1146

  
1147
  # save dunning fee pdf in filemanagement/webdav
1148
  if ($::instance_conf->get_doc_storage) {
1149
    SL::File->save(
1150
      object_id   => $dunning_id,
1151
      object_type => 'dunning',
1152
      mime_type   => 'application/pdf',
1153
      source      => 'created',
1154
      file_type   => 'document',
1155
      file_name   => $attachment_filename,
1156
      file_path   => "${spool}/$filename",
1157
    );
1158
  }
1159
  if ($::instance_conf->get_webdav_documents) {
1160
    my $webdav = SL::Webdav->new(
1161
      type     => 'dunning',
1162
      number   => $dunning_id,
1163
    );
1164
    my $webdav_file = SL::Webdav::File->new(
1165
      webdav   => $webdav,
1166
      filename => $attachment_filename,
1167
    );
1168
    $webdav_file->store(file => "${spool}/$filename");
1169
  }
1132
  push @{ $form->{DUNNING_PDFS} },         $filename;
1133
  push @{ $form->{DUNNING_PDFS_EMAIL} },   { 'path'       => "${spool}/$filename",
1134
                                             'name'       => $attachment_filename };
1135
  push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1136
                                             'path'       => "${spool}/$filename",
1137
                                             'name'       => $attachment_filename };
1170 1138

  
1171 1139
  $main::lxdebug->leave_sub();
1172 1140
}
......
1234 1202

  
1235 1203
  my $attachment_filename    = $form->get_formname_translation('invoice') . "_" . $invoice->invnumber . ".pdf";
1236 1204

  
1237
  push @{ $form->{DUNNING_PDFS} }, $file_name;
1238
  push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$file_name",
1239
                                           'name' => $attachment_filename };
1205
  push @{ $form->{DUNNING_PDFS} },         $file_name;
1206
  push @{ $form->{DUNNING_PDFS_EMAIL} },   { 'path'       => "${spool}/$file_name",
1207
                                             'name'       => $attachment_filename };
1208
  push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
1209
                                             'path'       => "${spool}/$file_name",
1210
                                             'name'       => $attachment_filename };
1240 1211

  
1241 1212
  $form->{recipient_locale}  = $saved_reicpient_locale;
1213
}
1214

  
1215
sub _store_pdf_to_webdav_and_filemanagement {
1216
  my ($dunning_id, $path, $name) =@_;
1217

  
1218
  my @errors;
1242 1219

  
1243
  # save original invoice pdf in filemanagement/webdav for dunning
1244 1220
  if ($::instance_conf->get_doc_storage) {
1245
    SL::File->save(
1246
      object_id   => $dunning_id,
1247
      object_type => 'dunning',
1248
      mime_type   => 'application/pdf',
1249
      source      => 'created',
1250
      file_type   => 'document',
1251
      file_name   => $attachment_filename,
1252
      file_path   => "${spool}/$file_name",
1253
    );
1221
    eval {
1222
      SL::File->save(
1223
        object_id   => $dunning_id,
1224
        object_type => 'dunning',
1225
        mime_type   => 'application/pdf',
1226
        source      => 'created',
1227
        file_type   => 'document',
1228
        file_name   => $name,
1229
        file_path   => $path,
1230
      );
1231
      1;
1232
    } or do {
1233
      push @errors, $::locale->text('Storing PDF in storage backend failed: #1', $@);
1234
    };
1254 1235
  }
1236

  
1255 1237
  if ($::instance_conf->get_webdav_documents) {
1256
    my $webdav = SL::Webdav->new(
1257
      type     => 'dunning',
1258
      number   => $dunning_id,
1259
    );
1260
    my $webdav_file = SL::Webdav::File->new(
1261
      webdav   => $webdav,
1262
      filename => $attachment_filename,
1263
    );
1264
    $webdav_file->store(file => "${spool}/$file_name");
1238
    eval {
1239
      my $webdav = SL::Webdav->new(
1240
        type     => 'dunning',
1241
        number   => $dunning_id,
1242
      );
1243
      my $webdav_file = SL::Webdav::File->new(
1244
        webdav   => $webdav,
1245
        filename => $name,
1246
      );
1247
      $webdav_file->store(file => $path);
1248
    } or do {
1249
      push @errors, $::locale->text('Storing PDF to webdav folder failed: #1', $@);
1250
    };
1265 1251
  }
1266 1252

  
1253
  return @errors;
1267 1254
}
1268 1255

  
1256

  
1269 1257
1;

Auch abrufbar als: Unified diff