commit 09f06c363b73435bf5b622741c31386fe1ebd120
Author: Tamino Steinert <tamino.steinert@tamino.st>
Date:   Fri Oct 13 13:03:32 2023 +0200

    Workflow: E-Mail → EK Rechnung/Gutschrift hinzugefügt

diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl
index 094c68bae..2512b2379 100644
--- a/bin/mozilla/ir.pl
+++ b/bin/mozilla/ir.pl
@@ -43,6 +43,7 @@ use SL::DB::Default;
 use SL::DB::Department;
 use SL::DB::Project;
 use SL::DB::PurchaseInvoice;
+use SL::DB::EmailJournal;
 use SL::DB::ValidityToken;
 use SL::DB::Vendor;
 use SL::DB::Tax;
@@ -102,6 +103,20 @@ sub add {
   $main::lxdebug->leave_sub();
 }
 
+sub add_from_email_journal {
+  die "No 'email_journal_id' was given." unless ($::form->{email_journal_id});
+  &add;
+}
+
+sub edit_with_email_journal_workflow {
+  my ($self) = @_;
+  die "No 'email_journal_id' was given." unless ($::form->{email_journal_id});
+  $::form->{workflow_email_journal_id}    = delete $::form->{email_journal_id};
+  $::form->{workflow_email_attachment_id} = delete $::form->{email_attachment_id};
+
+  &edit;
+}
+
 sub edit {
   $main::lxdebug->enter_sub();
 
@@ -818,6 +833,9 @@ sub storno {
 
   $main::auth->assert('vendor_invoice_edit');
 
+  $form->{email_journal_id}    = delete $form->{workflow_email_journal_id};
+  $form->{email_attachment_id} = delete $form->{workflow_email_attachment_id};
+
   if ($form->{storno}) {
     $form->error($locale->text('Cannot storno storno invoice!'));
   }
@@ -876,6 +894,9 @@ sub use_as_new {
 
   $main::auth->assert('vendor_invoice_edit');
 
+  $form->{email_journal_id}    = delete $form->{workflow_email_journal_id};
+  $form->{email_attachment_id} = delete $form->{workflow_email_attachment_id};
+
   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
   $form->{rowcount}--;
@@ -1046,6 +1067,14 @@ sub post {
     }
     # /saving the history
 
+    if ($form->{email_journal_id}) {
+      my $purchase_invoice = SL::DB::PurchaseInvoice->new(id => $form->{id})->load;
+      my $email_journal = SL::DB::EmailJournal->new(
+        id => delete $form->{email_journal_id}
+      )->load;
+      $email_journal->link_to_record_with_attachment($purchase_invoice, delete $::form->{email_attachment_id});
+    }
+
     my $redirect_url;
     if ('doc-tab' eq $form->{after_action}) {
       $redirect_url = build_std_url("script=ir.pl", 'action=edit', 'id=' . E($form->{id}), 'fragment=ui-tabs-docs');
diff --git a/templates/design40_webpages/ir/form_header.html b/templates/design40_webpages/ir/form_header.html
index 010e57b17..afe6bec19 100644
--- a/templates/design40_webpages/ir/form_header.html
+++ b/templates/design40_webpages/ir/form_header.html
@@ -4,7 +4,10 @@
 [% USE L %]
 [% USE P %]
 
-<h1>[% title %]</h1>
+<h1>
+  [% IF workflow_email_journal_id; LxERP.t8("Email Journal Workflow") _ " - "; END; %]
+  [% title %]
+</h1>
 
 [% SET follow_up_trans_info = invnumber _ ' (' _ vendor_obj.name _ ')' %]
 <script type="text/javascript" src="js/common.js"></script>
@@ -26,6 +29,10 @@
 [% IF !id %]
 [%   L.hidden_tag('form_validity_token', form_validity_token) %]
 [% END %]
+[% L.hidden_tag('email_journal_id',             email_journal_id) %]
+[% L.hidden_tag('email_attachment_id',          email_attachment_id) %]
+[% L.hidden_tag('workflow_email_journal_id',    workflow_email_journal_id) %]
+[% L.hidden_tag('workflow_email_attachment_id', workflow_email_attachment_id) %]
 
 [% INCLUDE 'common/flash.html' %]
 [% INCLUDE 'generic/set_longdescription.html' %]
@@ -34,6 +41,9 @@
 
 <ul>
   <li><a href="#ui-tabs-basic-data">[% 'Basic Data' | $T8 %]</a></li>
+  [% IF email_attachment_id || workflow_email_attachment_id %]
+    <li><a href="controller.pl?action=EmailJournal/attachment_preview&attachment_id=[% HTML.url(email_attachment_id || workflow_email_attachment_id) %]">[% 'Email Attachment Preview' | $T8 %]</a></li>
+  [% END %]
   [% IF INSTANCE_CONF.get_webdav %]
     <li><a href="#ui-tabs-webdav">[% 'WebDAV' | $T8 %]</a></li>
   [% END %]
@@ -55,6 +65,24 @@
 
 <div id="ui-tabs-basic-data">
 
+[% IF email_attachment_id || workflow_email_attachment_id%]
+  <div class="wrapper" id="email_attachment_wrapper">
+    [%
+      BLOCK panel_1;
+        P.email_journal.attachment_preview(
+             email_attachment_id || workflow_email_attachment_id,
+             style="height:600px"
+             );
+      END;
+      INCLUDE 'common/toggle_panel.html'
+        block_name='panel_1'
+        button_closed  = LxERP.t8('Show Attachment')
+        button_open    = LxERP.t8('Hide Attachment')
+        ;
+    %]
+  </div>
+[% END %]
+
 <div class="wrapper" id="wrapper-1">
   [% INCLUDE 'generic/toggle_wrapper.html' %]
 
diff --git a/templates/webpages/ir/form_header.html b/templates/webpages/ir/form_header.html
index 57ae0f068..1d0e8b869 100644
--- a/templates/webpages/ir/form_header.html
+++ b/templates/webpages/ir/form_header.html
@@ -2,7 +2,11 @@
 [%- USE HTML %]
 [%- USE LxERP %]
 [%- USE L %][%- USE P -%]
-<h1>[% title %]</h1>
+
+<h1>
+  [% IF workflow_email_journal_id; LxERP.t8("Email Journal Workflow") _ " - "; END; %]
+  [% title %]
+</h1>
 
 [%- SET follow_up_trans_info = invnumber _ ' (' _ vendor_obj.name _ ')' %]
 <script type="text/javascript" src="js/common.js"></script>
@@ -24,6 +28,10 @@
 [% IF !id %]
 [%   L.hidden_tag('form_validity_token', form_validity_token) %]
 [% END %]
+[% L.hidden_tag('email_journal_id',             email_journal_id) %]
+[% L.hidden_tag('email_attachment_id',          email_attachment_id) %]
+[% L.hidden_tag('workflow_email_journal_id',    workflow_email_journal_id) %]
+[% L.hidden_tag('workflow_email_attachment_id', workflow_email_attachment_id) %]
 
 [%- INCLUDE 'common/flash.html' %]
 [%- INCLUDE 'generic/set_longdescription.html' %]
@@ -31,6 +39,9 @@
 <div id="ir_tabs" class="tabwidget">
  <ul>
   <li><a href="#ui-tabs-basic-data">[% 'Basic Data' | $T8 %]</a></li>
+[% IF email_attachment_id || workflow_email_attachment_id %]
+  <li><a href="controller.pl?action=EmailJournal/attachment_preview&attachment_id=[% HTML.url(email_attachment_id || workflow_email_attachment_id) %]">[% 'Email Attachment Preview' | $T8 %]</a></li>
+[% END %]
 [%- IF INSTANCE_CONF.get_webdav %]
   <li><a href="#ui-tabs-webdav">[% 'WebDAV' | $T8 %]</a></li>
 [%- END %]
