..
  This file is part of GNU TALER.
  Copyright (C) 2014-2026 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 2.1, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>

  @author Bohdan Potuzhnyi
  @author Volodymyr Potuzhnyi

.. _libeufinconnector_dolibarr_transactions_outgoing:

Outgoing Transactions
=====================

.. contents::
  :depth: 1
  :local:

This module supports the following outgoing payments:

1. Supplier order invoices
2. Customer order credit notes

Customer order credit note
--------------------------

Firstly, create a credit note for some invoice. It must use bank transfer and
the same bank account as the one configured with LibEuFin Connector, label 1.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn1.png
   :alt: Customer credit note configured for bank transfer
   :width: 720px
   :align: center

   Customer credit note configured for bank transfer.

After this, you need to create a payment to the customer through this credit
note. Enter the amount, label 1, and press **Pay back**, label 2.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn2.png
   :alt: Creating a customer payback from a credit note
   :width: 720px
   :align: center

   Creating a customer payback from a credit note.

After this, go to the module, label 1, go to the transactions page, label 2,
and press **Collect outgoing**, label 3. As soon as it updates, you will see a
new entry like label 4. Since Dolibarr knows the bank account for this
customer, it sets it by default, but of course you might want to change it. For
this, go to the transaction page, label 5.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn3.png
   :alt: Collecting outgoing customer credit note payments
   :width: 720px
   :align: center

   Collecting outgoing customer credit note payments.

For outgoing bank accounts, you can select among the bank accounts connected to
the customer to whom we are trying to make a payment, using the dropdown at
label 1.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn4.png
   :alt: Selecting the recipient bank account for an outgoing payment
   :width: 720px
   :align: center

   Selecting the recipient bank account for an outgoing payment.

As soon as you have selected the recipient account as you wanted, you might
want to actually send it to the bank. For this, mainly 2 options are present:

1. Send selected open
2. Send all open

The first option exists so that with checkboxes, label 1, you can select which
transactions you want to send, label 2. And of course there is
**Send all open**, label 3, if you want to send all of them together.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn5.png
   :alt: Sending selected or all open outgoing payments
   :width: 720px
   :align: center

   Sending selected or all open outgoing payments.

You can verify that the transaction was actually sent by investigating your
bank. Here is a sample screenshot from my test PostFinance account, where we
can see the sent transaction, label 1, being present.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn6.png
   :alt: Outgoing payment visible in the test bank account
   :width: 720px
   :align: center

   Outgoing payment visible in the test bank account.

Of course, as I do not provide you with access to it, you might want to verify
this yourself. For this, navigate to the tutorial page, label 1, then press
**Show all transactions**, label 2. After some time, console output appears,
showing the data stored in the database of the libeufin-nexus module. This is
different from the Dolibarr module you work with, and in the demo setup it is
the closest thing to the bank.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn7.png
   :alt: Demo screen showing transactions stored in libeufin-nexus
   :width: 720px
   :align: center

   Demo screen showing transactions stored in libeufin-nexus.

And as such, you know how to make outgoing payments for customer invoice credit
notes.

Supplier order invoice
----------------------

As always, you need to create a supplier invoice. As an example, you can check
the next photo. The only thing is that it is not verified yet. To progress, you
have to verify it.

.. figure:: ../../images/libeufinconnector-dolibarr/so1.png
   :alt: Supplier invoice example in Dolibarr
   :width: 720px
   :align: center

   Supplier invoice example in Dolibarr.

Afterwards, you need to add a payment to it. Enter the amount, label 1, and
press **Pay**, label 2, in the next picture.

.. figure:: ../../images/libeufinconnector-dolibarr/so2.png
   :alt: Adding a supplier invoice payment
   :width: 720px
   :align: center

   Adding a supplier invoice payment.

As soon as you have done it, you need to go to the module page, label 1, then
go to the transaction page, label 2, collect outgoing payment, label 3. In this
example I use **Send all open**, label 4.

.. figure:: ../../images/libeufinconnector-dolibarr/so3.png
   :alt: Collecting and sending supplier invoice outgoing payments
   :width: 720px
   :align: center

   Collecting and sending supplier invoice outgoing payments.

After some time, while it is being submitted to libeufin-nexus, you will see
that the transaction status changes to ``Submitted``.

.. figure:: ../../images/libeufinconnector-dolibarr/so4.png
   :alt: Supplier invoice outgoing payment submitted to libeufin-nexus
   :width: 720px
   :align: center

   Supplier invoice outgoing payment submitted to libeufin-nexus.

You can also verify that the outgoing transaction is recorded in the same way
as for the customer order credit note. Here we can see this supplier order in
the libeufin-nexus transaction output.

.. figure:: ../../images/libeufinconnector-dolibarr/cocn7.png
   :alt: libeufin-nexus transaction output containing the supplier order payment
   :width: 720px
   :align: center

   libeufin-nexus transaction output containing the supplier order payment.

Alternatively, it also shows up at the bank website. In my case, it is the
PostFinance test account. We can see this transaction highlighted with label 1.

.. figure:: ../../images/libeufinconnector-dolibarr/so5.png
   :alt: Supplier outgoing payment visible in the test bank account
   :width: 720px
   :align: center

   Supplier outgoing payment visible in the test bank account.

As such, you now know how outgoing transactions work with this module.

Next step
---------

As you have observed how outgoing transactions work, you are really welcome to
check the :ref:`libeufinconnector_dolibarr_transactions_incoming` tutorial. If
you still have not installed the module, check
:ref:`libeufinconnector_dolibarr_install_config`.

For details on the standard Dolibarr objects used here, also check the official
Dolibarr documentation for
`customer invoices <https://wiki.dolibarr.org/index.php/Module_Customers_Invoices>`_
and
`supplier invoices <https://wiki.dolibarr.org/index.php/Module_Suppliers_Invoices>`_.
