Metadata-Version: 2.4
Name: juntagrico-billing
Version: 1.7.7
Summary: Send and manage bills in juntagrico.
Author-email: juntagrico <python@juntagrico.org>
License:                    GNU LESSER GENERAL PUBLIC LICENSE
                               Version 3, 29 June 2007
        
         Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
         Everyone is permitted to copy and distribute verbatim copies
         of this license document, but changing it is not allowed.
        
        
          This version of the GNU Lesser General Public License incorporates
        the terms and conditions of version 3 of the GNU General Public
        License, supplemented by the additional permissions listed below.
        
          0. Additional Definitions.
        
          As used herein, "this License" refers to version 3 of the GNU Lesser
        General Public License, and the "GNU GPL" refers to version 3 of the GNU
        General Public License.
        
          "The Library" refers to a covered work governed by this License,
        other than an Application or a Combined Work as defined below.
        
          An "Application" is any work that makes use of an interface provided
        by the Library, but which is not otherwise based on the Library.
        Defining a subclass of a class defined by the Library is deemed a mode
        of using an interface provided by the Library.
        
          A "Combined Work" is a work produced by combining or linking an
        Application with the Library.  The particular version of the Library
        with which the Combined Work was made is also called the "Linked
        Version".
        
          The "Minimal Corresponding Source" for a Combined Work means the
        Corresponding Source for the Combined Work, excluding any source code
        for portions of the Combined Work that, considered in isolation, are
        based on the Application, and not on the Linked Version.
        
          The "Corresponding Application Code" for a Combined Work means the
        object code and/or source code for the Application, including any data
        and utility programs needed for reproducing the Combined Work from the
        Application, but excluding the System Libraries of the Combined Work.
        
          1. Exception to Section 3 of the GNU GPL.
        
          You may convey a covered work under sections 3 and 4 of this License
        without being bound by section 3 of the GNU GPL.
        
          2. Conveying Modified Versions.
        
          If you modify a copy of the Library, and, in your modifications, a
        facility refers to a function or data to be supplied by an Application
        that uses the facility (other than as an argument passed when the
        facility is invoked), then you may convey a copy of the modified
        version:
        
           a) under this License, provided that you make a good faith effort to
           ensure that, in the event an Application does not supply the
           function or data, the facility still operates, and performs
           whatever part of its purpose remains meaningful, or
        
           b) under the GNU GPL, with none of the additional permissions of
           this License applicable to that copy.
        
          3. Object Code Incorporating Material from Library Header Files.
        
          The object code form of an Application may incorporate material from
        a header file that is part of the Library.  You may convey such object
        code under terms of your choice, provided that, if the incorporated
        material is not limited to numerical parameters, data structure
        layouts and accessors, or small macros, inline functions and templates
        (ten or fewer lines in length), you do both of the following:
        
           a) Give prominent notice with each copy of the object code that the
           Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the object code with a copy of the GNU GPL and this license
           document.
        
          4. Combined Works.
        
          You may convey a Combined Work under terms of your choice that,
        taken together, effectively do not restrict modification of the
        portions of the Library contained in the Combined Work and reverse
        engineering for debugging such modifications, if you also do each of
        the following:
        
           a) Give prominent notice with each copy of the Combined Work that
           the Library is used in it and that the Library and its use are
           covered by this License.
        
           b) Accompany the Combined Work with a copy of the GNU GPL and this license
           document.
        
           c) For a Combined Work that displays copyright notices during
           execution, include the copyright notice for the Library among
           these notices, as well as a reference directing the user to the
           copies of the GNU GPL and this license document.
        
           d) Do one of the following:
        
               0) Convey the Minimal Corresponding Source under the terms of this
               License, and the Corresponding Application Code in a form
               suitable for, and under terms that permit, the user to
               recombine or relink the Application with a modified version of
               the Linked Version to produce a modified Combined Work, in the
               manner specified by section 6 of the GNU GPL for conveying
               Corresponding Source.
        
               1) Use a suitable shared library mechanism for linking with the
               Library.  A suitable mechanism is one that (a) uses at run time
               a copy of the Library already present on the user's computer
               system, and (b) will operate properly with a modified version
               of the Library that is interface-compatible with the Linked
               Version.
        
           e) Provide Installation Information, but only if you would otherwise
           be required to provide such information under section 6 of the
           GNU GPL, and only to the extent that such information is
           necessary to install and execute a modified version of the
           Combined Work produced by recombining or relinking the
           Application with a modified version of the Linked Version. (If
           you use option 4d0, the Installation Information must accompany
           the Minimal Corresponding Source and Corresponding Application
           Code. If you use option 4d1, you must provide the Installation
           Information in the manner specified by section 6 of the GNU GPL
           for conveying Corresponding Source.)
        
          5. Combined Libraries.
        
          You may place library facilities that are a work based on the
        Library side by side in a single library together with other library
        facilities that are not Applications and are not covered by this
        License, and convey such a combined library under terms of your
        choice, if you do both of the following:
        
           a) Accompany the combined library with a copy of the same work based
           on the Library, uncombined with any other library facilities,
           conveyed under the terms of this License.
        
           b) Give prominent notice with the combined library that part of it
           is a work based on the Library, and explaining where to find the
           accompanying uncombined form of the same work.
        
          6. Revised Versions of the GNU Lesser General Public License.
        
          The Free Software Foundation may publish revised and/or new versions
        of the GNU Lesser General Public License from time to time. Such new
        versions will be similar in spirit to the present version, but may
        differ in detail to address new problems or concerns.
        
          Each version is given a distinguishing version number. If the
        Library as you received it specifies that a certain numbered version
        of the GNU Lesser General Public License "or any later version"
        applies to it, you have the option of following the terms and
        conditions either of that published version or of any later version
        published by the Free Software Foundation. If the Library as you
        received it does not specify a version number of the GNU Lesser
        General Public License, you may choose any version of the GNU Lesser
        General Public License ever published by the Free Software Foundation.
        
          If the Library as you received it specifies that a proxy can decide
        whether future versions of the GNU Lesser General Public License shall
        apply, that proxy's public statement of acceptance of any version is
        permanent authorization for you to choose that version for the
        Library.
        
Project-URL: Homepage, https://www.juntagrico.org
Project-URL: Issues, https://github.com/juntagrico/juntagrico-billing/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Other Audience
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: juntagrico>=1.7.0
Requires-Dist: lxml>=4.9.3
Requires-Dist: python-stdnum>=1.16
Requires-Dist: qrbill>=1.1.0
Requires-Dist: svglib==1.5.1
Dynamic: license-file

# juntagrico-billing


[![juntagrico-ci](https://github.com/juntagrico/juntagrico-billing/actions/workflows/juntagrico-ci.yml/badge.svg?branch=main&event=push)](https://github.com/juntagrico/juntagrico-billing/actions/workflows/juntagrico-ci.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/f1e8af41b78f052add70/maintainability)](https://codeclimate.com/github/juntagrico/juntagrico-billing/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/f1e8af41b78f052add70/test_coverage)](https://codeclimate.com/github/juntagrico/juntagrico-billing/test_coverage)
[![image](https://img.shields.io/github/last-commit/juntagrico/juntagrico-billing.svg)](https://github.com/juntagrico/juntagrico-billing)
[![image](https://img.shields.io/github/commit-activity/y/juntagrico/juntagrico-billing)](https://github.com/juntagrico/juntagrico-billing)

This is an extension for juntagrico. You can find more information about juntagrico here
(https://github.com/juntagrico/juntagrico).

It provides the following features for juntagrico:
* creating managing bills (invoices) for juntagrico subscriptions
* display of bills as HTML or PDF
* support for swiss qr bill with reference number
* manage payments for bills
* reading camt.054 payment files (in connection with qr bills and refnumer)
* bookkeeping export covering bills and payments

## Installation

Install juntagrico-billing via pip
`pip install juntagrico-billing`

or add it to your main django projects `requirements.txt`:
`juntagrico-billing`

You may also install from github source (or add it to `requirements.txt`):
`pip install git+https://github.com/juntagrico/juntagrico-billing.git`

In your `juntagrico.settings.py` add `juntagrico_billing` somewhere **above** `juntagrico`:
```python
INSTALLED_APPS = (
    'juntagrico_billing',
    'juntagrico',
    ...
```

In your urls.py you also need to add the new pattern:
```python
urlpatterns = [
    ...
    path('',include('juntagrico_billing.urls')),
]
```

As the billing app introduces its own database tables, you need to apply migrations after installing.
Execute `python manage.py migrate` in your main django project.

## Configuration

Set these in your `settings.py` to modify `juntagrico-billing`

### BILLS_USERMENU
  Set to True to add "bills" to the user menu.

  default value: False

### DUEDATE_NOTICE_URL
  Set the url of a page that explains the due date policy of your bills, if you have any.

  default value: ''

## Create settings object

`juntagrico-billing` uses a singleton `Settings` object to store some setting.
You need to create this settings object once in django admin.

- Log in to juntagrico and go to the admin UI at `https://<my juntagrico site>/admin`.
- You should see in admin a new section for juntagrico_billing
  ![grafik](https://user-images.githubusercontent.com/3380098/110239635-419b4600-7f48-11eb-8fb7-afed31983a2d.png)
- Add a new Settings object
  
  ![grafik](https://user-images.githubusercontent.com/3380098/110239725-b79fad00-7f48-11eb-9bb6-badecc6af93e.png)
  
- You need to specify a debtors account, just specify any digit code (e.g. `1100`)
- A default paymenttype is mandatory too. You may create one directly from the settings dialog:
  ![grafik](https://user-images.githubusercontent.com/3380098/110239772-f9c8ee80-7f48-11eb-8866-7844d234e971.png)
- Save your settings object. There must be only one settings object.

## Create a business year

Billing is done on the base of a business-year. A business-year denotes the time period for creating bills.
Usually this will correspond to a calendar year (1.1 - 31.1 of a year). It is possible to use different timespans though.
Business-years should be consecutive.

Business years are managed in django admin UI. 

- Log in to `/admin` and create a new businessyear object
  ![grafik](https://user-images.githubusercontent.com/3380098/110240002-20d3f000-7f4a-11eb-8118-aebd351228b4.png)


## Billing

Billing is based on the activation and deactivation dates of subscriptions (and extrasubscriptions) in juntagrico.
At any time you may create all needed invoices (bills) for a certain business-year.

In juntagrico you should see the `Bills and Bookkeeping` Menu, if you are assigned bookkeeping rights.

Go to `Bills` and choose the desired business-year.
Switch to the `Generate bills` tab. The amount of pending bills for the businessyear should then be displayed.
This may take some time depending on the number of subscriptions and members in your system.
![grafik](https://user-images.githubusercontent.com/3380098/110240325-ae640f80-7f4b-11eb-8288-4f2ec16811f9.png)

Pressing the `Generate` button will create these bills.
They may be viewed afterwards on the `all` tab of the bills list.
![grafik](https://user-images.githubusercontent.com/3380098/110240404-0a2e9880-7f4c-11eb-9a5b-3ad92af46c50.png)

### Modifying or adding bills

There are two modes to view an existing bill object:
- admin view of the bill. click on the first column of a bill row to open the bill in django admin.
- user view of the bill. click on the last columdn of a bill row to open the bill as the user will see it.

If a bill created via `Generate` is incorrect, proceed as follows:
- delete the bill in the django admin UI
- correct the subscription settings
  - in most cases this will involve adjusting the activation or deactivation date of the subscription / extrasubscription
- re-create the bill by going to the `Generate bills` tab on the `Bills` list.
  - if you only modified one subscription, it should say `1 pending bill`
  - click on `Generate` to re-create the bill based on the modified settings

The same procedure applies if a new subscription or subscription part (extrasubscription) is added after bills for a business-year have been generated.
If there already is a bill for the same member and you want the additional parts to appear on the same bill, you may delete the existing bill and regenerate it like described above.
Deleting a bill is only possible if there are no payments on it.
If you add parts without deleting an existing bill, then a new bill will be added for the member.

### Adding custom items to a bill

In addition to subscription and extrasubscription parts, a bill may also contain custom items.
Custom items may be used for stuff like
- correcting overpaid bills
- adding special credit for a certain member (work instead of paying)
- adding additional contributions (solidarity contributions)

For each kind of custom item you need to define a custom Bill item type in django admin:
![grafik](https://user-images.githubusercontent.com/3380098/110240808-f126e700-7f4d-11eb-9e73-35f43138a48e.png)

You need to specify a description and a booking account for the custom item type.

You may then add custom item types on a bill in the django admin view of the bill:
![grafik](https://user-images.githubusercontent.com/3380098/110240939-8c1fc100-7f4e-11eb-8e62-45393ddd1600.png)

## Bookkeeping Export
TBD
