MassRecordCreationAndPrinting - MassInvoiceCreatePrint: Auftrag schliessen
authorWerner Hahn <wh@futureworldsearch.net>
Sat, 5 Feb 2022 07:41:58 +0000 (08:41 +0100)
committerWerner Hahn <wh@futureworldsearch.net>
Sat, 5 Feb 2022 07:50:06 +0000 (08:50 +0100)
SL/BackgroundJob/MassRecordCreationAndPrinting.pm
SL/Controller/MassInvoiceCreatePrint.pm

index 371e587..ebd20e1 100644 (file)
@@ -11,6 +11,7 @@ use SL::DB::Invoice;
 use SL::DB::Printer;
 use SL::SessionFile;
 use SL::Template;
+use SL::ARAP;
 use SL::Locale::String qw(t8);
 use SL::Helper::MassPrintCreatePDF qw(:all);
 use SL::Helper::CreatePDF qw(:all);
@@ -41,6 +42,7 @@ sub create_invoices {
 
   my $job_obj = $self->{job_obj};
   my $db      = $job_obj->db;
+  my $dbh     = SL::DB->client->dbh;
 
   $job_obj->set_data(status => CONVERTING_DELIVERY_ORDERS())->save;
 
@@ -55,6 +57,11 @@ sub create_invoices {
       my $invoice              = $sales_delivery_order->convert_to_invoice(%conversion_params);
 
       die $db->error if !$invoice;
+
+      ARAP->close_orders_if_billed('dbh'     => $dbh,
+                                   'arap_id' => $invoice->id,
+                                   'table'   => 'ar',);
+
       # update shop status
       my @linked_shop_orders = $invoice->linked_records(
         from      => 'ShopOrder',
index 0981260..bfaf0a2 100644 (file)
@@ -19,6 +19,7 @@ use SL::Helper::File qw(store_pdf append_general_pdf_attachments doc_storage_ena
 use SL::Helper::Flash;
 use SL::Locale::String;
 use SL::SessionFile;
+use SL::ARAP;
 use SL::System::TaskServer;
 use Rose::Object::MakeMethods::Generic
 (
@@ -57,6 +58,7 @@ sub action_create_invoices {
   }
 
   my $db = SL::DB::Invoice->new->db;
+  my $dbh = SL::DB->client->dbh;
   my @invoices;
   my @already_closed_delivery_orders;
 
@@ -73,6 +75,11 @@ sub action_create_invoices {
 
       } else {
         my $invoice = $delivery_order->convert_to_invoice() || die $db->error;
+
+        ARAP->close_orders_if_billed('dbh'     => $dbh,
+                                     'arap_id' => $invoice->id,
+                                     'table'   => 'ar',);
+
         push @invoices, $invoice;
       }
     }