Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fdbb484e

Von Jan Büren vor mehr als 1 Jahr hinzugefügt

  • ID fdbb484eec453a2676992459ecf78d14aa5008e8
  • Vorgänger 69597c45
  • Nachfolger 4870f180

Background Job um den Bezahlstatus in Shopware6 zu setzen

Unterschiede anzeigen:

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

  
3
use strict;
4

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

  
7
use SL::DB::Invoice;
8
use SL::Locale::String qw(t8);
9
use SL::Shop;
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 $today   = ($data->{datepaid}) ? DateTime->from_kivitendo($data->{datepaid}) : DateTime->today_local;
17

  
18
  my $paid_invoices = SL::DB::Manager::Invoice->get_all(query => [ and => [ datepaid => { ge => $today }, amount  =>   \'paid'  ]]);
19

  
20
  my @shoporders;
21
  foreach my $invoice (@{ $paid_invoices }) {
22
    # check if we have a shop order invoice
23
    my @linked_shop_orders = $invoice->linked_records(
24
                               from => 'ShopOrder',
25
                               via  => ['DeliveryOrder','Order'],
26
                             );
27
    my $shop_order = $linked_shop_orders[0][0];
28
    if ( $shop_order ) {
29
       #do update
30
       push @shoporders, $shop_order->shop_ordernumber;
31
       next if $dry_run;
32
       my $shop_config = SL::DB::Manager::Shop->get_first( query => [ id => $shop_order->shop_id ] );
33
       my $shop = SL::Shop->new( config => $shop_config );
34
       $shop->connector->set_orderstatus($shop_order->shop_trans_id, "paid");
35
    }
36
  }
37
  return t8("The following Shop Orders: ") . join (', ', @shoporders) . $dry_run ? t8(" would be set to the state 'paid'") : t8(" have been so to the state 'paid'");
38
}
39

  
40
1;
41

  
42
__END__
43

  
44
=encoding utf8
45

  
46
=head1 NAME
47

  
48
SL::BackgroundJob::ShopwareSetPaid
49

  
50
Background job for setting the shopware state paid for shopware orders
51

  
52
With the default values the job should be run once a day after all payments are booked.
53

  
54
=head1 SYNOPSIS
55

  
56
Accepts two params 'dry_run' and 'datepaid'.
57
If 'dry_run' has trueish vale, the job simply returns what would have been done in the Background Job Journal.
58
If 'datepaid' is set all Invoices with a datepaid higher or equal the 'datepaid' value are checked. Date should be
59
in the correct system locales. If ommitted datepaid will be the current date.
60

  
61

  
62
=head1 AUTHOR
63

  
64
Jan Büren
65

  
66
=cut

Auch abrufbar als: Unified diff