edoc invoice link for DATEV Administration Guide
Breadcrumbs

Edit invoice via hook before processing in edoc invoice link for DATEV

You can adjust the invoice data before processing using a hook. Thus, you can, for example, add your own calculations (customer-specific) or individual fields.

Suppose you do not want to transfer the items individually, but add them up using the G/L account and cost center. You can implement this procedure with an individual function.

You can save PHP files with your individual functions in the installation directory at <app>/data/persistent/hooks/prepare_invoice.

You must follow these principles when creating individual functions:

  • The files must contain a class with the same name as the file.

  • The class must extend the App\AbstractPrepareInvoice class.

  • You must implement the exec() function and implement your logic there.

  • You can access the following properties with the extension of the App\CustomFunction class:

    • helper: Is an ActionHelper object with which you can execute edoc automate actions. For more information about the actions see the edoc automate guide.

    • invoice: Is an object of the App\Invoice class passed by reference and contains the following properties:

      • header: Contains the header data of the current invoice.

      • status: Contains the status information of the current invoice.

      • items: Contains the line item data of the current invoice with the transfer data of the invoice.

Example of an individual function

PHP
<?php

namespace Edoc\InvoiceLink\Custom;

use App\AbstractPrepareInvoice;

class GroupPositions extends AbstractPrepareInvoice
{
    private array $newPositions = [];
    private array $fields = [
      "net_amount",
      "vat_amount",
        "gross_amount"
    ];

    public function exec()
    {
        $rowIndex = -1;
        foreach ($this->invoice->positions as $position) {
            // Build a unique id for position
            $account = $position["account"] ?? "";
            $vatPercent = $position["vat_percent"] ?? "";
            $costCenter = $position["cost_center"] ?? "";
            $keyField = $account . "_" . $costCenter . "_" . $vatPercent;

            if (array_key_exists($keyField, $this->newPositions)) {
                foreach ($this->fields as $field) {
                    if (!empty($position[$field])) { // Only add value if not empty
                        if (!empty($this->newPositions[$keyField][$field])) {
                            $this->newPositions[$keyField][$field] += $position[$field];
                        } else {
                            $this->newPositions[$keyField][$field] = $position[$field];
                        }
                    }
                }
            } else {
                $position["row_index"] = $rowIndex++;
                $this->newPositions[$keyField] = $position;
            }
        }

        $this->invoice->positions = $this->newPositions;
    }
}

Here's how

  1. Create the GroupPositions.php file in the persistent folder of the app (via WebDAV: data/persistent/hooks/prepare_invoice/GroupPositions.php).

  2. Supplement or replace your individual logic.

Things to know

Files in the persistent folder are not overwritten when the version is updated. At the same time, however, these files are not included in the *.eax file when exporting an app. So if you move the server, for example, you will have to copy the files manually.

Prevent an export to the accounting system

You can also use the entry point to prevent an invoice from being exported to the accounting system. To do this, use the abortProcessing(string $reason) method within the entry point. Enter a reason for stopping the export in the $reason parameter. An activity and a posting journal will still be created for the invoice as a successful export, but with the note that the invoice was not transferred to a DATEV file and with your reason.

This function is often used to cancel the processing of invoices with a purchase order reference, as these invoices are posted via a different system.

This function is currently only available for edoc invoice link for DATEV classic.

Here's how

  1. Create the file AbortProcessing.php in the persistent folder of the app (via WebDAV: data/persistent/hooks/prepare_invoice/AbortProcessing.php).

  2. Supplement or replace your individual logic.

PHP
<?php

namespace Edoc\InvoiceLink\Custom;

use App\AbstractPrepareInvoice;

class AbortProcessing extends AbstractPrepareInvoice
{
    public function exec()
    {
        if ($this->invoice->header['vendor_id'] == '9500') {
            $this->abortProcessing(
                "Invoices of supplier 9500 <company name> are processed by another system."
            );
        }
    }
}