# Plugin InvoiceS

## About

The plugin provides the following functionality:

- creation process-related invoices with automatically generated number;

- generation printing form out of them;

- providing printing form documents to be attached and sent in process message like Email.

## Setup

| You can see (queue Plugin Invoice) the plugin operation in Demo System.

### Process Type

The plugin assigns month-based invoices to processes, in type configuration of those have to be enabled Invoices tab.

    invoice:processShowInvoices=1

In the type configuration should be also defined two parameters, use their IDs in <paramCostId> and <paramContractDateId>

Detailed explanation of configuration properties is given below.

### Config

Make sure the plugin is enabled and append to the configuration:

#### Positions

Invoice positions contain amount information, any possible positions is defined in configuration.

    invoice:position.{@inc:cnt}.id=<posId>
    invoice:position.{@cnt}.title=<posTitle>

Where:

- <posId> - unique lowercase string for position’s identification

- <posTitle> - title.

#### Invoice Type

Invoice are divided to types, each of those is defined in configuration as:

    invoice:type.<ID>.title=<TITLE>
    invoice:type.<ID>.template=<template>
    # or directly a template JSP path
    #invoice:type.<ID>.template.jsp=<templatePath>
    invoice:type.<ID>.customer=<customerId>

- <ID> - unique type numeric ID, must not be changed after beginning of using it;

- <TITLE> - type title;

- <template> - template name, supported values: eu_en, ru_ru;

- <templatePath> - alternatively to template name, may be defined a direct path to a JSP template, must be placed in custom area, for example: /WEB-INF/jspf/user/plugin/invoice/doc/my_my.jsp;

- <customerId> - customer ID, which parameters are used for generation of printing forms.

#### Numeration

Each invoice gets an unique number when generated, that can be configured:

    invoice:type.<ID>.number.class=<numberClass>
    invoice:type.<ID>.number.pattern=<patternNumber>

- <numberClass> - Java class implementing org.bgerp.plugin.bil.invoice.num.NumberProvider, org.bgerp.plugin.bil.invoice.num.PatternBasedNumberProvider does pattern-based numeration.

- <patternNumber> - numeration pattern for PatternBasedNumberProvider, supports the following macros:

  - (${process_id:000000}) - process ID zero-padded from left for a needed length, this case to 6 digits;

  - (${date_from:yyyyMM}) - first date of the invoice from month formatted using date format;

  - (${date_to:yyyyMM}) - last date of the invoice to month formatted using date format;

  - (${number_in_month_for_process:00}) - sequential invoice number for a given process, also zero-padded from left.

### Positions

For adding positions to a generated invoice are charged position providers.

    invoice:type.<ID>.provider.{@inc:cnt}.class=<providerClass>
    invoice:type.<ID>.provider.{@cnt}.expression=<jexlExpression>

- <providerClass> - Java class implementing org.bgerp.plugin.bil.invoice.pos.PositionProvider, org.bgerp.plugin.bil.invoice.pos.ExpressionPositionProvider executed JEXL script for adding positions;

- <jexlExpression> - JEXL expression with additional objects:

  - invoice invoice object of org.bgerp.plugin.bil.invoice.model.Invoice

  - process invoice process ru.bgcrm.model.process.Process

  - processParam process parameters map, result of parameters method in org.bgerp.dao.param.ParamValueDAO

## Usage

On the screen below is shown process card with activated plugin. Invoices are shown in reverse order, the last one is placed on the top of the table.

Clicking on the invoice’s number opens generated HTML printing form.

To generate a new invoice, press Add button, select invoice type and required month’s range. They are will be suggested automatically based ont the last process' invoice.

On the next step are shown and can be edited invoice positions.

After correction of generated positions list and create. In existing invoices the position list may be edited after creation using popup menu.

The menu provides also items to mark invoices paid / unpaid or delete them.

HTML printing forms of invoices are offered to be attached to messages.

### Invoice Register Report

The Report allows to mark paid invoices and observe already paid for the current user in a chosen month.