Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ddea4659

Von Jan Büren vor 8 Monaten hinzugefügt

  • ID ddea46594d9207aac6c8b39995690cc8df1680ec
  • Vorgänger 956805a6
  • Nachfolger f0c62c1b

kix18: Hintergrund-Job um geschlossene Tickets mit VK-Aufträgen zu synchronisieren

Unterschiede anzeigen:

SL/BackgroundJob/KIXSetTicketState.pm
1
package SL::BackgroundJob::KIXSetTicketState;
2

  
3
use strict;
4

  
5
use parent qw(SL::BackgroundJob::Base);
6

  
7
use SL::DB::Order;
8
use SL::KIX18Client qw(:all);
9

  
10

  
11
sub run {
12
  my ($self, $db_obj)     = @_;
13
  my $data       = $db_obj->data_as_hash;
14

  
15
  my $dry_run         = ($data->{dry_run}) ? 1 : 0;
16
  my $closed_state_id = $data->{closed_state_id} || 4;
17

  
18
  my $open_ticket_id   = SL::DB::Manager::OrderStatus->find_by(name => 'Ticket offen')->id;
19
  my $closed_ticket_id = SL::DB::Manager::OrderStatus->find_by(name => 'Ticket erledigt')->id;
20

  
21
  my $orders = SL::DB::Manager::Order->get_all(query => [ order_status_id   => $open_ticket_id,
22
                                                          record_type       => 'sales_order',
23
                                                         '!ticket_id'       => undef            ]);
24

  
25
  my $c = SL::KIX18Client->new();
26

  
27
  my @ord;
28
  foreach my $order (@{ $orders }) {
29
    next unless $order->ticket_id;
30

  
31
    my $ticket = $c->get_ticket(ticket_id => $order->ticket_id);
32

  
33
    if ($ticket->{Ticket}{StateID} == $closed_state_id)  {
34
      push @ord, $order->ordnumber;
35

  
36
      next if $dry_run;
37
      $order->order_status_id($closed_ticket_id);
38
      $order->save;
39
    }
40
  }
41
  return "Ticket-Status auf erledigt gesetzt bei:" . join (', ', @ord) . ($dry_run ? " TESTLAUF noch nicht getan" : " getan");
42
}
43

  
44
1;
45

  
46
__END__
47

  
48
=encoding utf8
49

  
50
=head1 NAME
51

  
52
SL::BackgroundJob::KIXSetTicketState
53
Background job for state updates of all sales orders who have ticket_id.
54
Data Options include dry_run and closed_state_id which defaults to 4:
55

  
56
 dry_run: 0
57
 closed_state_id: 4
58

  
59
=head1 SYNOPSIS
60

  
61
=head1 AUTHOR
62

  
63
Jan Büren
64

  
65
=cut

Auch abrufbar als: Unified diff