Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ba486db5

Von Tamino Steinert vor 10 Monaten hinzugefügt

  • ID ba486db5677d155df96d54f3441de7e0404cdb88
  • Vorgänger deb7c2c1
  • Nachfolger 0861998a

EmailJournal: Basisfunktionalität fürs Verlinken und Neu erstellen von Belegen

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
8 8
use SL::DB::Employee;
9 9
use SL::DB::EmailJournal;
10 10
use SL::DB::EmailJournalAttachment;
11
use SL::DB::Order;
11 12
use SL::Helper::Flash;
12 13
use SL::Locale::String;
13 14
use SL::System::TaskServer;
......
22 23
__PACKAGE__->run_before('add_stylesheet');
23 24
__PACKAGE__->run_before('add_js');
24 25

  
26
my %RECORD_TYPES_INFO = (
27
  # Order
28
  Order => {
29
    controller => 'Order',
30
    model      => 'SL::DB::Order',
31
    types => [
32
      'purchase_order',
33
      'purchase_quotation_intake',
34
      'request_quotation',
35
      'sales_order',
36
      'sales_order_intake',
37
      'sales_quotation',
38
    ],
39
  },
40
);
41
my %RECORD_TYPE_TO_CONTROLLER =
42
  map {
43
    my $controller = $RECORD_TYPES_INFO{$_}->{controller};
44
    map { $_ => $controller } @{ $RECORD_TYPES_INFO{$_}->{types} }
45
  } keys %RECORD_TYPES_INFO;
46
my %RECORD_TYPE_TO_MODEL =
47
  map {
48
    my $model = $RECORD_TYPES_INFO{$_}->{model};
49
    map { $_ => $model } @{ $RECORD_TYPES_INFO{$_}->{types} }
50
  } keys %RECORD_TYPES_INFO;
51

  
25 52
#
26 53
# actions
27 54
#
......
56 83

  
57 84
  $self->setup_show_action_bar;
58 85
  $self->render('email_journal/show',
59
                title   => $::locale->text('View sent email'),
86
                title   => $::locale->text('View email'),
60 87
                back_to => $back_to);
61 88
}
62 89

  
......
78 105
  $self->send_file($ref, name => $attachment->name, type => $attachment->mime_type);
79 106
}
80 107

  
108
sub action_apply_record_action {
109
  my ($self) = @_;
110
  my $email_journal_id = $::form->{email_journal_id};
111
  my $attachment_id = $::form->{attachment_id};
112
  my $record_action = $::form->{record_action};
113
  my $vendor_id = $::form->{vendor_id};
114
  my $customer_id = $::form->{customer_id};
115

  
116
  if ( $record_action =~ s/^link_// ) { # remove prefix
117

  
118
    # Load record
119
    my $record_type = $record_action;
120
    my $record_id = $::form->{$record_type . "_id"};
121
    my $record_type_model = $RECORD_TYPE_TO_MODEL{$record_type};
122
    my $record = $record_type_model->new(id => $record_id)->load;
123
    my $email_journal = SL::DB::EmailJournal->new(id => $email_journal_id)->load;
124

  
125
    if ($attachment_id) {
126
      my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load;
127
      $attachment->add_file_to_record($record);
128
    }
129

  
130
    $email_journal->link_to_record($record);
131

  
132
    return $self->js->flash('info',  $::locale->text('Linked to e-mail ') . $record->displayable_name)->render();
133
  }
134

  
135
  my %additional_params = ();
136
  if ( $record_action =~ s/^customer_// ) {  # remove prefix
137
    $additional_params{customer_id} = $customer_id;
138
  } elsif ( $record_action =~ s/^vendor_// ) { # remove prefix
139
    $additional_params{vendor_id} = $vendor_id;
140
  }
141
  $additional_params{type} = $record_action;
142
  $additional_params{controller} = $RECORD_TYPE_TO_CONTROLLER{$record_action};
143

  
144
  $self->redirect_to(
145
    action           => 'add',
146
    email_journal_id => $email_journal_id,
147
    attachment_id    => $attachment_id,
148
    %additional_params,
149
  );
150
}
151

  
81 152
sub action_update_attachment_preview {
82 153
  my ($self) = @_;
83 154
  $::auth->assert('email_journal');
......
92 163
    ->replaceWith('#attachment_preview',
93 164
      SL::Presenter::EmailJournal::attachment_preview(
94 165
        $attachment,
95
        style => "width:489px;border:1px solid black;margin:9px"
166
        style => "width:655px;border:1px solid black;margin:9px"
96 167
      )
97 168
    )
98 169
    ->render();
......
110 181
# helpers
111 182
#
112 183

  
184
sub find_cv_from_email {
185
  my ($self, $cv_type, $email_journal) = @_;
186
  my $email_address = $email_journal->from;
187

  
188
  # search for customer or vendor or both
189
  my $customer;
190
  my $vendor;
191
  if ($cv_type ne 'vendor') {
192
    $customer = SL::DB::Manager::Customer->get_first(
193
      where => [
194
        or => [
195
          email => $email_address,
196
          cc    => $email_address,
197
          bcc   => $email_address,
198
          'contacts.cp_email' => $email_address,
199
          'contacts.cp_privatemail' => $email_address,
200
          'shipto.shiptoemail' => $email_address,
201
        ],
202
      ],
203
      with_objects => [ 'contacts', 'shipto' ],
204
    );
205
  } elsif ($cv_type ne 'customer') {
206
    $vendor = SL::DB::Manager::Vendor->get_first(
207
      where => [
208
        or => [
209
          email => $email_address,
210
          cc    => $email_address,
211
          bcc   => $email_address,
212
          'contacts.cp_email' => $email_address,
213
          'contacts.cp_privatemail' => $email_address,
214
          'shipto.shiptoemail' => $email_address,
215
        ],
216
      ],
217
      with_objects => [ 'contacts', 'shipto' ],
218
    );
219
  }
220

  
221
  return $customer || $vendor;
222
}
223

  
224
sub find_customer_from_email {
225
  my ($self, $email_journal) = @_;
226
  my $email_address = $email_journal->from;
227

  
228
  my $customer = SL::DB::Manager::Customer->get_first(
229
    where => [
230
      or => [
231
        email => $email_address,
232
        cc    => $email_address,
233
        bcc   => $email_address,
234
        'contacts.cp_email' => $email_address,
235
        'contacts.cp_privatemail' => $email_address,
236
        'shipto.shiptoemail' => $email_address,
237
      ],
238
    ],
239
    with_objects => [ 'contacts', 'shipto' ],
240
  );
241

  
242
  return $customer;
243
}
244

  
113 245
sub add_js {
114 246
  $::request->{layout}->use_javascript("${_}.js") for qw(
115 247
    kivi.EmailJournal

Auch abrufbar als: Unified diff