Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3a8be1b7

Von Tamino Steinert vor 7 Monaten hinzugefügt

  • ID 3a8be1b7fa19297314bfdf99f9b898986d1df9f1
  • Vorgänger 9734325f
  • Nachfolger 39aa38b2

EmailJournal: Templates überarbeitet und Verknüpfte Belege hinzugefügt

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;
12 11
use SL::Helper::Flash;
13
use SL::Locale::String;
12
use SL::Locale::String qw(t8);
14 13
use SL::System::TaskServer;
15 14
use SL::Presenter::EmailJournal;
16 15

  
16
use SL::DB::Order;
17
use SL::DB::Order::TypeData;
18
use SL::DB::DeliveryOrder;
19
use SL::DB::DeliveryOrder::TypeData;
20
use SL::DB::Reclamation;
21
use SL::DB::Reclamation::TypeData;
22
use SL::DB::Invoice;
23
use SL::DB::PurchaseInvoice;
24

  
25
use SL::DB::Manager::Customer;
26
use SL::DB::Manager::Vendor;
27

  
17 28
use Rose::Object::MakeMethods::Generic
18 29
(
19 30
  scalar                  => [ qw(entry) ],
......
24 35
__PACKAGE__->run_before('add_js');
25 36

  
26 37
my %RECORD_TYPES_INFO = (
27
  # Order
28 38
  Order => {
29 39
    controller => 'Order',
30 40
    model      => 'SL::DB::Order',
41
    types => SL::DB::Order::TypeData->valid_types(),
42
  },
43
  DeliveryOrder => {
44
    controller => 'DeliveryOrder',
45
    model      => 'SL::DB::DeliveryOrder',
46
    types => SL::DB::DeliveryOrder::TypeData->valid_types(),
47
  },
48
  Reclamation => {
49
    controller => 'Reclamation',
50
    model      => 'SL::DB::Reclamation',
51
    types => SL::DB::Reclamation::TypeData->valid_types(),
52
  },
53
  Invoice => {
54
    controller => 'ar.pl',
55
    model      => 'SL::DB::Invoice',
56
    types => [
57
      'ar_transaction',
58
      'invoice',
59
      'invoice_for_advance_payment',
60
      'invoice_for_advance_payment_storno',
61
      'final_invoice',
62
      'invoice_storno',
63
      'credit_note',
64
      'credit_note_storno',
65
    ],
66
  },
67
  PurchaseInvoice => {
68
    controller => 'ap.pl',
69
    model      => 'SL::DB::PurchaseInvoice',
31 70
    types => [
32
      'purchase_order',
33
      'purchase_quotation_intake',
34
      'request_quotation',
35
      'sales_order',
36
      'sales_order_intake',
37
      'sales_quotation',
71
      'ap_transaction',
72
      'purchase_invoice',
73
      'purchase_credit_note',
38 74
    ],
39 75
  },
40 76
);
......
81 117
    $::form->error(t8('You do not have permission to access this entry.'));
82 118
  }
83 119

  
120
  my @record_types_with_info = ();
121
  for my $record_class ('SL::DB::Order', 'SL::DB::DeliveryOrder', 'SL::DB::Reclamation') {
122
    my $valid_types = "${record_class}::TypeData"->valid_types();
123
    for my $type (@$valid_types) {
124

  
125
      my $type_data = SL::DB::Helper::TypeDataProxy->new($record_class, $type);
126
      push @record_types_with_info, {
127
        record_type    => $type,
128
        customervendor => $type_data->properties('customervendor'),
129
        text           => $type_data->text('type'),
130
      };
131
    }
132
  }
133
  push @record_types_with_info, (
134
    # invoice
135
    { record_type => 'ar_transaction'                    ,  customervendor => 'customer',  text => t8('AR Transaction')},
136
    { record_type => 'invoice'                           ,  customervendor => 'customer',  text => t8('Invoice') },
137
    { record_type => 'invoice_for_advance_payment'       ,  customervendor => 'customer',  text => t8('Invoice for Advance Payment')},
138
    { record_type => 'invoice_for_advance_payment_storno',  customervendor => 'customer',  text => t8('Storno Invoice for Advance Payment')},
139
    { record_type => 'final_invoice'                     ,  customervendor => 'customer',  text => t8('Final Invoice')},
140
    { record_type => 'invoice_storno'                    ,  customervendor => 'customer',  text => t8('Storno Invoice')},
141
    { record_type => 'credit_note'                       ,  customervendor => 'customer',  text => t8('Credit Note')},
142
    { record_type => 'credit_note_storno'                ,  customervendor => 'customer',  text => t8('Storno Credit Note')},
143
    # purchase invoice
144
    { record_type => 'ap_transaction'      ,  customervendor => 'vendor',  text => t8('AP Transaction')},
145
    { record_type => 'purchase_invoice'    ,  customervendor => 'vendor',  text => t8('Purchase Invoice')},
146
    { record_type => 'purchase_credit_note',  customervendor => 'vendor',  text => t8('Purchase Credit Note')},
147
  );
148

  
149
  my $customer_vendor = $self->find_customer_vendor_from_email($self->entry);
150

  
84 151
  $self->setup_show_action_bar;
85
  $self->render('email_journal/show',
86
                title   => $::locale->text('View email'),
87
                back_to => $back_to);
152
  $self->render(
153
    'email_journal/show',
154
    title    => $::locale->text('View email'),
155
    CUSTOMER_VENDOR => , $customer_vendor,
156
    CV_TYPE_FOUND => $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer',
157
    RECORD_TYPES_WITH_INFO => \@record_types_with_info,
158
    back_to  => $back_to
159
  );
88 160
}
89 161

  
90 162
sub action_show_attachment {
......
123 195

  
124 196
sub action_apply_record_action {
125 197
  my ($self) = @_;
126
  my $email_journal_id = $::form->{email_journal_id};
127
  my $attachment_id = $::form->{attachment_id};
128
  my $record_action = $::form->{record_action};
129
  my $vendor_id = $::form->{vendor_id};
130
  my $customer_id = $::form->{customer_id};
131

  
132
  if ( $record_action =~ s/^link_// ) { # remove prefix
133

  
134
    # Load record
135
    my $record_type = $record_action;
136
    my $record_id = $::form->{$record_type . "_id"};
137
    my $record_type_model = $RECORD_TYPE_TO_MODEL{$record_type};
138
    my $record = $record_type_model->new(id => $record_id)->load;
139
    my $email_journal = SL::DB::EmailJournal->new(id => $email_journal_id)->load;
140

  
141
    if ($attachment_id) {
142
      my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load;
143
      $attachment->add_file_to_record($record);
144
    }
145

  
146
    $email_journal->link_to_record($record);
147

  
148
    return $self->js->flash('info',  $::locale->text('Linked to e-mail ') . $record->displayable_name)->render();
198
  my $email_journal_id   = $::form->{email_journal_id};
199
  my $attachment_id      = $::form->{attachment_id};
200
  my $customer_vendor    = $::form->{customer_vendor_selection};
201
  my $customer_vendor_id = $::form->{"${customer_vendor}_id"};
202
  my $action             = $::form->{action_selection};
203
  my $record_type        = $::form->{"${customer_vendor}_record_type_selection"};
204
  my $record_id          = $::form->{"${record_type}_id"};
205

  
206
  if ($action eq 'linking') {
207
    return $self->link_and_add_attachment_to_record({
208
        email_journal_id    => $email_journal_id,
209
        attachment_id       => $attachment_id,
210
        record_type         => $record_type,
211
        record_id           => $record_id,
212
      });
149 213
  }
150 214

  
151 215
  my %additional_params = ();
152
  if ( $record_action =~ s/^customer_// ) {  # remove prefix
153
    $additional_params{customer_id} = $customer_id;
154
  } elsif ( $record_action =~ s/^vendor_// ) { # remove prefix
155
    $additional_params{vendor_id} = $vendor_id;
216
  if ($action eq 'create_new') {
217
    $additional_params{action} = 'add_from_email_journal';
218
    $additional_params{"${customer_vendor}_id"} = $customer_vendor_id;
219
  } else {
220
    $additional_params{action} = 'edit_from_email_journal';
221
    $additional_params{id} = $record_id;
156 222
  }
157
  $additional_params{type} = $record_action;
158
  $additional_params{controller} = $RECORD_TYPE_TO_CONTROLLER{$record_action};
159 223

  
160 224
  $self->redirect_to(
161
    action              => 'add_from_email_journal',
225
    controller          => $RECORD_TYPE_TO_CONTROLLER{$record_type},
226
    type                => $record_type,
162 227
    from_id             => $email_journal_id,
163 228
    from_type           => 'email_journal',
164 229
    email_attachment_id => $attachment_id,
......
198 263
# helpers
199 264
#
200 265

  
201
sub find_cv_from_email {
202
  my ($self, $cv_type, $email_journal) = @_;
266
sub link_and_add_attachment_to_record {
267
 my ($self, $params) = @_;
268

  
269
  my $email_journal_id   = $params->{email_journal_id};
270
  my $attachment_id      = $params->{attachment_id};
271
  my $record_type        = $params->{record_type};
272
  my $record_id          = $params->{record_id};
273

  
274
  my $record_type_model = $RECORD_TYPE_TO_MODEL{$record_type};
275
  my $record = $record_type_model->new(id => $record_id)->load;
276
  my $email_journal = SL::DB::EmailJournal->new(id => $email_journal_id)->load;
277

  
278
  if ($attachment_id) {
279
    my $attachment = SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load;
280
    $attachment->add_file_to_record($record);
281
  }
282

  
283
  $email_journal->link_to_record($record);
284

  
285
  return $self->js->flash('info',  $::locale->text('Linked e-mail and attachment to ') . $record->displayable_name)->render();
286
}
287

  
288
sub find_customer_vendor_from_email {
289
  my ($self, $email_journal, $cv_type) = @_;
203 290
  my $email_address = $email_journal->from;
291
  $email_address =~ s/.*<(.*)>/$1/; # address can look like "name surname <email_address>"
204 292

  
205
  # search for customer or vendor or both
206
  my $customer;
207
  my $vendor;
208
  if ($cv_type ne 'vendor') {
209
    $customer = SL::DB::Manager::Customer->get_first(
293
  # Separate query otherwise cv without contacts and shipto is not found
294
  my $customer_vendor;
295
  foreach my $manager (qw(SL::DB::Manager::Customer SL::DB::Manager::Vendor)) {
296
    $customer_vendor ||= $manager->get_first(
210 297
      where => [
211 298
        or => [
212 299
          email => $email_address,
213 300
          cc    => $email_address,
214 301
          bcc   => $email_address,
215
          'contacts.cp_email' => $email_address,
216
          'contacts.cp_privatemail' => $email_address,
217
          'shipto.shiptoemail' => $email_address,
218 302
        ],
219 303
      ],
220
      with_objects => [ 'contacts', 'shipto' ],
221 304
    );
222
  } elsif ($cv_type ne 'customer') {
223
    $vendor = SL::DB::Manager::Vendor->get_first(
305
    $customer_vendor ||= $manager->get_first(
224 306
      where => [
225 307
        or => [
226
          email => $email_address,
227
          cc    => $email_address,
228
          bcc   => $email_address,
229 308
          'contacts.cp_email' => $email_address,
230 309
          'contacts.cp_privatemail' => $email_address,
310
        ],
311
      ],
312
      with_objects => [ 'contacts'],
313
    );
314
    $customer_vendor ||= $manager->get_first(
315
      where => [
316
        or => [
231 317
          'shipto.shiptoemail' => $email_address,
232 318
        ],
233 319
      ],
234
      with_objects => [ 'contacts', 'shipto' ],
320
      with_objects => [ 'shipto' ],
235 321
    );
236 322
  }
237 323

  
238
  return $customer || $vendor;
324
  return $customer_vendor;
239 325
}
240 326

  
241 327
sub find_customer_from_email {

Auch abrufbar als: Unified diff