Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 48ef5a7c

Von Tamino Steinert vor 10 Monaten hinzugefügt

  • ID 48ef5a7cdf3e4e8a6163c3f9bda6f2a1e7fbcb04
  • Vorgänger b8dfb10a
  • Nachfolger 6e00af5b

EmailJournal: Suche nach E-Mail von Kunde und Lieferant getrennt

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
254 254
  my @record_types_with_info = $self->get_record_types_with_info();
255 255
  my %record_types_to_text   = $self->get_record_types_to_text();
256 256

  
257
  my $customer_vendor = $self->find_customer_vendor_from_email($self->entry);
258
  my $cv_type = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
259

  
260
  my $record_types = $self->record_types_for_customer_vendor_type_and_action($cv_type, 'workflow_record');
257
  my $customer = $self->find_customer_vendor_from_email('customer', $self->entry);
258
  my $vendor   = $self->find_customer_vendor_from_email('vendor'  , $self->entry);
259
  my $cv_type_found;
260
  $cv_type_found   = 'vendor' if $self->entry->record_type eq 'ap_transaction';
261
  $cv_type_found ||= 'vendor' if defined $vendor;
262
  $cv_type_found ||= 'customer';
263

  
264
  my $record_types = $self->record_types_for_customer_vendor_type_and_action(
265
    $cv_type_found, 'workflow_record'
266
  );
261 267

  
262 268
  $self->setup_show_action_bar;
263
  my $cv_type_found = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
264
  # overwrite on record_type
265
  $cv_type_found = 'vendor' if $self->entry->record_type eq 'ap_transaction';
266 269
  $self->render(
267 270
    'email_journal/show',
268 271
    title                  => $::locale->text('View email'),
269
    CUSTOMER_VENDOR        => $customer_vendor,
272
    CUSTOMER               => $customer,
273
    VENDOR                 => $vendor,
270 274
    CV_TYPE_FOUND          => $cv_type_found,
271 275
    RECORD_TYPES_WITH_INFO => \@record_types_with_info,
272 276
    RECORD_TYPES_TO_TEXT   => \%record_types_to_text,
......
607 611
}
608 612

  
609 613
sub find_customer_vendor_from_email {
610
  my ($self, $email_journal, $cv_type) = @_;
614
  my ($self, $cv_type, $email_journal) = @_;
615

  
616
  my $manager = $cv_type eq 'customer' ? 'SL::DB::Manager::Customer'
617
              : $cv_type eq 'vendor'   ? 'SL::DB::Manager::Vendor'
618
              : die "No valid customer vendor option: $cv_type";
619

  
611 620
  my $email_address = $email_journal->from;
612 621
  $email_address =~ s/.*<(.*)>/$1/; # address can look like "name surname <email_address>"
613 622

  
614 623
  # Separate query otherwise cv without contacts and shipto is not found
615 624
  my $customer_vendor;
616
  foreach my $manager (qw(SL::DB::Manager::Customer SL::DB::Manager::Vendor)) {
617
    $customer_vendor ||= $manager->get_first(
618
      where => [
619
        or => [
620
          email => $email_address,
621
          cc    => $email_address,
622
          bcc   => $email_address,
623
        ],
625
  $customer_vendor ||= $manager->get_first(
626
    where => [
627
      or => [
628
        email => $email_address,
629
        cc    => $email_address,
630
        bcc   => $email_address,
624 631
      ],
625
    );
626
    $customer_vendor ||= $manager->get_first(
627
      where => [
628
        or => [
629
          'contacts.cp_email' => $email_address,
630
          'contacts.cp_privatemail' => $email_address,
631
        ],
632
    ],
633
  );
634
  $customer_vendor ||= $manager->get_first(
635
    where => [
636
      or => [
637
        'contacts.cp_email' => $email_address,
638
        'contacts.cp_privatemail' => $email_address,
632 639
      ],
633
      with_objects => [ 'contacts'],
634
    );
640
    ],
641
    with_objects => [ 'contacts'],
642
  );
643
  $customer_vendor ||= $manager->get_first(
644
    where => [
645
      or => [
646
        'shipto.shiptoemail' => $email_address,
647
      ],
648
    ],
649
    with_objects => [ 'shipto' ],
650
  );
651
  if ($manager eq 'SL::DB::Manager::Customer') {
635 652
    $customer_vendor ||= $manager->get_first(
636 653
      where => [
637 654
        or => [
638
          'shipto.shiptoemail' => $email_address,
655
          'additional_billing_addresses.email' => $email_address,
639 656
        ],
640 657
      ],
641
      with_objects => [ 'shipto' ],
658
      with_objects => [ 'additional_billing_addresses' ],
642 659
    );
643
    if ($manager eq 'SL::DB::Manager::Customer') {
644
      $customer_vendor ||= $manager->get_first(
645
        where => [
646
          or => [
647
            'additional_billing_addresses.email' => $email_address,
648
          ],
649
        ],
650
        with_objects => [ 'additional_billing_addresses' ],
651
      );
652
    }
653 660
  }
654 661

  
655 662
  # if no exact match is found search for domain and match only on one hit
......
657 664
    my $email_domain = $email_address;
658 665
    $email_domain =~ s/.*@(.*)/$1/;
659 666
    my @domain_hits_cusotmer_vendor = ();
660
    foreach my $manager (qw(SL::DB::Manager::Customer SL::DB::Manager::Vendor)) {
661
      my @domain_hits = ();
662
      push @domain_hits, @{$manager->get_all(
663
        where => [
664
          or => [
665
            email => {ilike => "%$email_domain"},
666
            cc    => {ilike => "%$email_domain"},
667
            bcc   => {ilike => "%$email_domain"},
668
          ],
667
    my @domain_hits = ();
668
    push @domain_hits, @{$manager->get_all(
669
      where => [
670
        or => [
671
          email => {ilike => "%$email_domain"},
672
          cc    => {ilike => "%$email_domain"},
673
          bcc   => {ilike => "%$email_domain"},
669 674
        ],
670
      )};
671
      push @domain_hits, @{$manager->get_all(
672
        where => [
673
          or => [
674
            'contacts.cp_email'       => {ilike => "%$email_domain"},
675
            'contacts.cp_privatemail' => {ilike => "%$email_domain"},
676
          ],
675
      ],
676
    )};
677
    push @domain_hits, @{$manager->get_all(
678
      where => [
679
        or => [
680
          'contacts.cp_email'       => {ilike => "%$email_domain"},
681
          'contacts.cp_privatemail' => {ilike => "%$email_domain"},
677 682
        ],
678
        with_objects => [ 'contacts'],
679
      )};
680
      push @domain_hits, @{$manager->get_all(
681
        where => [
682
          or => [
683
            'shipto.shiptoemail' => {ilike => "%$email_domain"},
684
          ],
683
      ],
684
      with_objects => [ 'contacts'],
685
    )};
686
    push @domain_hits, @{$manager->get_all(
687
      where => [
688
        or => [
689
          'shipto.shiptoemail' => {ilike => "%$email_domain"},
685 690
        ],
686
        with_objects => [ 'shipto' ],
687
      )};
691
      ],
692
      with_objects => [ 'shipto' ],
693
    )};
694
    push @domain_hits, @{$manager->get_all(
695
      where => [
696
        or => [
697
          'shipto.shiptoemail' => {ilike => "%$email_domain"},
698
        ],
699
      ],
700
      with_objects => [ 'shipto' ],
701
    )};
702
    if ($manager eq 'SL::DB::Manager::Customer') {
688 703
      push @domain_hits, @{$manager->get_all(
689 704
        where => [
690 705
          or => [
691
            'shipto.shiptoemail' => {ilike => "%$email_domain"},
706
            'additional_billing_addresses.email' => {ilike => "%$email_domain"},
692 707
          ],
693 708
        ],
694
        with_objects => [ 'shipto' ],
709
        with_objects => [ 'additional_billing_addresses' ],
695 710
      )};
696
      if ($manager eq 'SL::DB::Manager::Customer') {
697
        push @domain_hits, @{$manager->get_all(
698
          where => [
699
            or => [
700
              'additional_billing_addresses.email' => {ilike => "%$email_domain"},
701
            ],
702
          ],
703
          with_objects => [ 'additional_billing_addresses' ],
704
        )};
705
      }
706
      # get every customer_vendor only once
707
      my %id_to_customer_vendor = ();
708
      $id_to_customer_vendor{$_->id} = $_ for @domain_hits;
709
      push @domain_hits_cusotmer_vendor, $id_to_customer_vendor{$_} for keys %id_to_customer_vendor;
710 711
    }
711

  
712
    if (scalar @domain_hits_cusotmer_vendor == 1) {
713
      $customer_vendor = $domain_hits_cusotmer_vendor[0];
712
    # update on only one unique customer_vendor
713
    if (scalar @domain_hits) {
714
      my $first_customer_vendor = $domain_hits[0];
715
      unless (any {$_->id != $first_customer_vendor->id} @domain_hits) {
716
        $customer_vendor = $first_customer_vendor;
717
      }
714 718
    }
715 719
  }
716 720

  
templates/design40_webpages/email_journal/show.html
178 178
    <div id="record_selection_div">
179 179
      <div id="filter_div"><div class="input-panel" style="margin:0">
180 180
        [% FOREACH cv_option = [
181
             ['customer', 'Customer', 1],
182
             ['vendor',   'Vendor',   0],
181
             ['customer', 'Customer'],
182
             ['vendor',   'Vendor'  ],
183 183
             ] %]
184 184
        [% SET cv_type        = cv_option.0 %]
185 185
        [% SET cv_name        = cv_option.1 %]
186
        [% SET cv_is_cusotmer = cv_option.2 %]
187 186
        <div
188 187
          id="[% cv_type _ "_div" %]" class="col"
189 188
          style=[% IF cv_type == CV_TYPE_FOUND %] "display:block" [% ELSE %] "display:none" [% END %]
190 189
          >
191 190
          [% P.customer_vendor.picker(
192 191
               cv_type _ "_id",
193
               CUSTOMER_VENDOR.is_customer == cv_is_cusotmer ? CUSTOMER_VENDOR : undef,
192
               cv_type == 'customer' ? CUSTOMER : VENDOR,
194 193
               type=cv_type, class="wi-normal", placeholder=LxERP.t8(cv_name)
195 194
               onchange='kivi.EmailJournal.update_record_list();'
196 195
               ) %]
templates/webpages/email_journal/show.html
170 170
    <div id="record_selection_div">
171 171
      <div style="display:flex">
172 172
        [% FOREACH cv_option = [
173
             ['customer', 'Customer', 1],
174
             ['vendor',   'Vendor',   0],
173
             ['customer', 'Customer'],
174
             ['vendor',   'Vendor'  ],
175 175
             ] %]
176 176
        [% SET cv_type        = cv_option.0 %]
177 177
        [% SET cv_name        = cv_option.1 %]
178
        [% SET cv_is_cusotmer = cv_option.2 %]
179 178
        <div
180 179
          id="[% cv_type _ "_div" %]"
181 180
          style=[% IF cv_type == CV_TYPE_FOUND %] "display:block" [% ELSE %] "display:none" [% END %]
182 181
          >
183 182
          [% P.customer_vendor.picker(
184 183
               cv_type _ "_id",
185
               CUSTOMER_VENDOR.is_customer == cv_is_cusotmer ? CUSTOMER_VENDOR : undef,
184
               cv_type == 'customer' ? CUSTOMER : VENDOR,
186 185
               type=cv_type, class="wi-normal", placeholder=LxERP.t8(cv_name)
187 186
               onchange='kivi.EmailJournal.update_record_list();'
188 187
               ) %]

Auch abrufbar als: Unified diff