edoc invoice link for DATEV Administration Guide
Breadcrumbs

Create individual functions in edoc invoice link for DATEV

In the administration at <app_path>/admin, you can add a specific function tailored to your needs in the field configuration in addition to the header data and line item data of the invoice. An individual function is always relevant if you want to make specific calculations or, for example, combine the value of several invoice fields.

You can save PHP files with your individual functions in the installation directory at <app>/data/persistent/fieldFunctions. Always create a single PHP file for each function and save the PHP file with a meaningful file name. You will need the file name for the field configuration.

You must follow these principles when creating individual functions:

  • The files must contain a class with the same name as the file itself (without file extension).

  • The class must extend the App\CustomFunction class.

  • The exec() function is called from the interface and the return value is used for the field value.

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

    • logger: Is an object of the PSR\Log\LoggerInterface class. The logger object can be used to write debug information and error messages to the log file.

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

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

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

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

    • position: Is an array. If line item data is processed, this array is filled with the data of the current line item. Otherwise, the array contains the data of the first line item, if available.

    • api: Is an object of the edoc\appserver\ScriptAPI\Action class with the helper methods for data sources and actions. For more information about the actions see the edoc automate guide.

Example of an individual function

PHP
<?php

use App\CustomFunction;

class PrefixVendorId extends CustomFunction
{
    public function exec()
    {
        $this->logger->debug("Start processing PrefixVendorId");

        $data = "PREFIX_" . ($this->invoice->header["vendor_id"] ?? "");

        // Use position:
        //$account = $this->position["account"];

        // Use Script API i.E. do something with d.3
        //$this->api->getDatasource("d3");

        $this->logger->debug("End processing PrefixVendorId");

        return $data;
    }
}

Then add the individual function in the field configuration of your app.

Here's how

  1. Create a new field configuration or switch to an existing configuration.

  2. Under Mapping type, select the entry Individual function.

  3. Enter the name of the class under Mapping details. Enter the name of the PHP file without the file extension (e.g. ManipulateVendorName instead of ManipulateVendorName.php).

The function is executed when the field value is determined.