1 package SL::BackgroundJob::ShopwareSetPaid;
5 use parent qw(SL::BackgroundJob::Base);
8 use SL::Locale::String qw(t8);
12 my ($self, $db_obj) = @_;
13 my $data = $db_obj->data_as_hash;
15 my $dry_run = ($data->{dry_run}) ? 1 : 0;
16 my $today = ($data->{datepaid}) ? DateTime->from_kivitendo($data->{datepaid}) : DateTime->today_local;
18 my $paid_invoices = SL::DB::Manager::Invoice->get_all(query => [ and => [ datepaid => { ge => $today }, amount => \'paid' ]]);
21 foreach my $invoice (@{ $paid_invoices }) {
22 # check if we have a shop order invoice
23 my @linked_shop_orders = $invoice->linked_records(
25 via => ['DeliveryOrder','Order'],
27 my $shop_order = $linked_shop_orders[0][0];
30 push @shoporders, $shop_order->shop_ordernumber;
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_order_transaction_status($shop_order->shop_ordernumber, "paid");
38 return t8("No valid invoice(s) found") if scalar @shoporders == 0;
40 my $message = t8("The following Shop Orders: ") . join (', ', @shoporders);
41 $message .= $dry_run ? t8(" would be set to the state 'paid'") : t8(" have been set to the state 'paid'");
54 SL::BackgroundJob::ShopwareSetPaid
56 Background job for setting the shopware state paid for shopware orders
58 With the default values the job should be run once a day after all payments are booked.
62 Accepts two params 'dry_run' and 'datepaid'.
63 If 'dry_run' has trueish vale, the job simply returns what would have been done in the Background Job Journal.
64 If 'datepaid' is set all Invoices with a datepaid higher or equal the 'datepaid' value are checked. Date should be
65 in the correct system locales. If ommitted datepaid will be the current date.