code: public function onInsert(ResourceEventInterface $event)
      {
          $invoice = $this->getInvoiceFromEvent($event);
  
          // Generate number and key
          $changed = $this->generateNumber($invoice);
  
          // Updates the invoice data
          $changed |= $this->invoiceBuilder->update($invoice);
  
          // Updates the totals
          $changed |= $this->updateTotals($invoice);
  
          if ($changed) {
              $this->persistenceHelper->persistAndRecompute($invoice, false);
          }
  
          $sale = $this->getSaleFromInvoice($invoice);
          if ($sale instanceof InvoiceSubjectInterface) {
              $sale->addInvoice($invoice); // TODO wtf ?
          }
  
          $this->scheduleSaleContentChangeEvent($sale);
      }
docs: Insert event handler.
  
  @param ResourceEventInterface $event