Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.INVOICE.INVOICE

This package exports classes and functions used for accounting: invoices, customers/providers, movements, taxes... License: AGPL3 Copyright Pascal J. Bourguignon 1990 - 2012 This program 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 3 of the License, or (at your option) any later version. This program 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 this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

LOAD-JOURNAL (PATH &KEY (VERBOSE *LOAD-VERBOSE*) (PRINT *LOAD-PRINT*))

DO: Load the journal at PATH.

Private

* (&REST ARGS)

DO: A Generic multiplication with numbers or amounts.

+ (&REST ARGS)

DO: A Generic addition with numbers or amounts.

- (&REST ARGS)

DO: A Generic substraction with numbers or amounts.

/ (&REST ARGS)

DO: A Generic division with numbers or amounts.

ALIGN-FOLLOWING-LINES (TEXT LEFT-MARGIN)

DO: Format the TEXT inserting LEFT-MARGIN spaces before each line but the first.

AMOUNT-CURRENCY (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

AMOUNT-VALUE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

AMOUNT-ZERO (CURRENCY)

RETURN: A null amount of the given currency.

CALENDAR-CURRENT-DATE

RETURN: The date today.

CLEAN-TITLE-FOR-FILE-NAME (TITLE-STRING)

RETURN: A string containing the first word of title-string as plain ASCII. DO: Remove accents from the returned word.

DATE-DAY (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

DATE-IN-YEAR-TRIMESTRE (DATE YEAR TRIMESTRE)

RETURN: Whether the given date is within the given YEAR and TRIMESTRE.

DATE-MONTH (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

DATE-TO-UNIVERSAL-TIME (DATE-STRING)

DATE-STRING: A date in the ISO8601 format 'YYYY-MM-DD'. RETURN: A number of seconds since 1900-01-01 00:00:00 GMT.

DATE-YEAR (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

EURO-ROUND (MAGNITUDE CURRENCY)

MAGNITUDE: A REAL CURRENCY: The currency of the amount. RETURN: An integer in minor unit rounded according to the Euro rule.

EURO-VALUE-ROUND (VALUE)

VALUE: A REAL CURRENCY: The currency of the amount. RETURN: An integer in minor unit rounded according to the Euro rule.

JOURNAL-PRINT-HEADER (YEAR TRIMESTRE &KEY (STREAM T))

PRIVATE

JOURNAL-PRINT-TOTALS (TOTALS &KEY (STREAM T))

PRIVATE

JOURNAL-PRINT-TRAILER (&KEY (STREAM T))

PRIVATE

JOURNAL-SPLIT-AND-JUSTIFY-DESCRIPTION (DESCRIPTION WIDTH)

PRIVATE

JOURNAL-TOTALS-OF-ENTRIES (ENTRIES)

PRIVATE RETURN: a list containing the totals: credit-ht credit-vat debit-ht debit-vat-inversion debit-vat-corriente.

LOCAL-TIME-ZONE

RETURN: The local time zone, as returned by GET-DECODED-TIME.

MAKE-MOVEMENT (DATE AMOUNT-TTC VAT-RATE NIF FAC-L DESCRIPTION KIND)

RETURN: A new instance of MOVEMENT filled with the given data .

MAKE-MOVEMENT-FROM-INVOICE (INVOICE)

RETURN: A new instance of MOVEMENT filled with data from invoice.

SHOW-TVA (MONTANT-HT &KEY (STREAM T) (VAT-RATE 4/25 VAT-RATE-P) (IRPF NIL IRPF-P) (LANGUAGE ES) (ALT-LANGUAGE ES))

Affiche le montant HT donné, la TVA, le montant TTC. En option le taux de TVA. La facture est dans la devise du montant. Une ou deux langues peuvent aussi être indiquées (:es, :fr, :en). Une option :irpf ou :no-irpf peut être indiquée pour forcer la déduction IRPF, sinon elle est appliquée par défaut uniquement dans le cas où le taux de TVA est 16% et la langue est 'es (sans langue secondaire) et la currency :EUR. (show-tva #978m750.00 :vat-rate 16/100 :language :en :alt-language :es) donne : ---------------------------------------------------- ----------------- (Base imponible ) Total : 750.00 EUR (IVA 16.0 % ) VAT 16.0 % : + 120.00 EUR (Total factura ) Total VAT Incl. : = 870.00 EUR ---------------------------------------------------- -----------------

SPLIT-LINES (TEXT &KEY DELETE-EMPTY-LINES)

DELETE-EMPTY-LINES: When true, lines that are stripped empty are removed. RETURN: A list of stripped and splitted lines from the TEXT.

TRIM-JUSTIFY-AND-SPLIT-TEXT (TEXT WIDTH)

DOES: Trim spaces on each line. justify each paragraph. RETURN: The justified text.

UNIVERSAL-TIME-TO-DATE (UTIME)

RETURN: the given universal time formated in the ISO8601 YYYY-MM-DD format.

Undocumented

/= (&REST ARGS)

< (&REST ARGS)

<= (&REST ARGS)

= (&REST ARGS)

> (&REST ARGS)

>= (&REST ARGS)

SETFAMOUNT-CURRENCY (NEW-VALUE INSTANCE)

SETFAMOUNT-VALUE (NEW-VALUE INSTANCE)

AMOUNTP (OBJECT)

COPY-AMOUNT (INSTANCE)

COPY-DATE (INSTANCE)

CURRENCY-SYNTAX (STREAM CHAR INFIX)

DATE-AFTER (A B)

SETFDATE-DAY (NEW-VALUE INSTANCE)

DATE-FORMAT (UTIME &KEY (LANGUAGE EN))

DATE-FROM-STRING (YYYY-MM-DD)

SETFDATE-MONTH (NEW-VALUE INSTANCE)

DATE-P (OBJECT)

SETFDATE-YEAR (NEW-VALUE INSTANCE)

KIND-TO-ORDER (KIND)

MAKE-AMOUNT (&KEY ((CURRENCY DUM0) NIL) ((VALUE DUM1) 0))

MAKE-DATE (&KEY ((YEAR DUM1005) NIL) ((MONTH DUM1006) NIL) ((DAY DUM1007) NIL))

MCERROR (OPERATION AMOUNTS FORMAT-CONTROL &REST FORMAT-ARGUMENTS)

TYPES-OF-ARGUMENTS (ARGS)

MACRO

Public

JOURNAL-ENTRY (DATE AMOUNT-TTC VAT-RATE NIF FAC DESCRIPTION KIND)

DOES: Add a new journal entry. AMOUNT-TTC is the total paid (including VAT) expressed in Euros. VAT-RATE is the V.A.T percentage.

MAKE-BANK-REFERENCE (&REST ARGS)

RETURN: A new instance of BANK-REFERENCE with the given initargs.

PERSON (&REST ARGS)

DO: Add to the *INVOICE-SET* a new FISCAL-PERSON instance created with the give initargs.

Undocumented

INVOICE (&REST ARGS)

Private

MAKE-COMPARISON-METHOD (NAME OPERATOR)

DO: Generate a comparison method.

Undocumented

LONGEST-LOCALIZED-LENGTH (TABLE LANGUAGE FIELDS)

GENERIC-FUNCTION

Public

GENERATE (INVOICE &KEY STREAM VERBOSE LANGUAGE (LANGUAGE ES LANGUAGE-P) (VERBOSE NIL) (STREAM T) &ALLOW-OTHER-KEYS)

DO: Generate this invoice into a file in the directory *INVOICE-DIRECTORY-PATH*. RETURN: The path to the file generated.

Private

Undocumented

ABS (SELF)

ADD-ENTRY (SELF ENTRY)

ADD-INVOICE (SELF INVOICE)

ADD-LINE (SELF LINE)

ADD-PERSON (SELF PERSON &OPTIONAL FISC)

AMOUNT-MAGNITUDE (SELF)

COMPUTE-TOTALS (SELF)

CREDIT-HT (SELF)

CREDIT-VAT (SELF)

DEBIT-HT (SELF)

DEBIT-VAT (SELF)

DEBIT-VAT-CORRIENTE (SELF)

DEBIT-VAT-INVERSION (SELF)

ENSURE-SORTED (SELF)

EXTRACT (SELF YEAR TRIMESTRE)

FORMAT-ARGUMENTS (CONDITION)

SETFFORMAT-ARGUMENTS (NEW-VALUE CONDITION)

FORMAT-CONTROL (CONDITION)

SETFFORMAT-CONTROL (NEW-VALUE CONDITION)

GET-INVOICE-WITH-ISSUER-AND-NUMBER (SELF ISSUER-FISCAL-ID INVOICE-NUMBER)

GET-PERSON-WITH-FISCAL-ID (SELF FISCAL-ID)

IS-CREDIT (SELF)

IS-REFUND (SELF)

MOVEMENT-ERROR-AMOUNT-TTC (CONDITION)

SETFMOVEMENT-ERROR-AMOUNT-TTC (NEW-VALUE CONDITION)

MOVEMENT-ERROR-DATE (CONDITION)

SETFMOVEMENT-ERROR-DATE (NEW-VALUE CONDITION)

MOVEMENT-ERROR-DESCRIPTION (CONDITION)

SETFMOVEMENT-ERROR-DESCRIPTION (NEW-VALUE CONDITION)

MOVEMENT-ERROR-FAC-L (CONDITION)

SETFMOVEMENT-ERROR-FAC-L (NEW-VALUE CONDITION)

MOVEMENT-ERROR-KIND (CONDITION)

SETFMOVEMENT-ERROR-KIND (NEW-VALUE CONDITION)

MOVEMENT-ERROR-NIF (CONDITION)

SETFMOVEMENT-ERROR-NIF (NEW-VALUE CONDITION)

MOVEMENT-ERROR-VAT-RATE (CONDITION)

SETFMOVEMENT-ERROR-VAT-RATE (NEW-VALUE CONDITION)

MULTI-CURRENCY-ERROR-AMOUNTS (CONDITION)

SETFMULTI-CURRENCY-ERROR-AMOUNTS (NEW-VALUE CONDITION)

MULTI-CURRENCY-ERROR-OPERATION (CONDITION)

SETFMULTI-CURRENCY-ERROR-OPERATION (NEW-VALUE CONDITION)

NEGATIVEP (SELF)

POSITIVEP (SELF)

RESET (SELF)

ROUND (SELF &OPTIONAL DIVISOR)

WRITE-INVOICE-FILE (SELF &KEY LANGUAGE (LANGUAGE EN LANGUAGE-P))

ZEROP (SELF)

SLOT-ACCESSOR

Public

BANK-REFERENCE (OBJECT)

The bank reference of the person.

SETFBANK-REFERENCE (NEW-VALUE OBJECT)

The bank reference of the person.

TRIMESTRE (JOURNAL)

The RETURN: The quarter of the journal (1 2 3 or 4).

SETFTRIMESTRE (NEW-VALUE OBJECT)

Set the RETURN: The quarter of the journal (1 2 3 or 4).

Private

ACCOUNT-NUMBER (OBJECT)

The account number. It should be an IBAN in Europe.

SETFACCOUNT-NUMBER (NEW-VALUE OBJECT)

The account number. It should be an IBAN in Europe.

ADDRESS (OBJECT)

The address of the person.

SETFADDRESS (NEW-VALUE OBJECT)

The address of the person.

AMOUNT-HT (SELF)

The amount excluding the taxes of this line.

SETFAMOUNT-HT (NEW-VALUE OBJECT)

The amount excluding the taxes of this line.

AMOUNT-TTC (OBJECT)

(number) The amount paid (including taxes).

SETFAMOUNT-TTC (NEW-VALUE OBJECT)

(number) The amount paid (including taxes).

AMOUNT-VAT (OBJECT)

(number) The VAT of the movement.

SETFAMOUNT-VAT (NEW-VALUE OBJECT)

(number) The VAT of the movement.

BANK-ADDRESS (OBJECT)

The address of the bank.

SETFBANK-ADDRESS (NEW-VALUE OBJECT)

The address of the bank.

BANK-NAME (OBJECT)

The name of the bank.

SETFBANK-NAME (NEW-VALUE OBJECT)

The name of the bank.

BENEFICIARY-NAME (OBJECT)

The beneficiary's name.

SETFBENEFICIARY-NAME (NEW-VALUE OBJECT)

The beneficiary's name.

BRANCH-NAME (OBJECT)

The name of the branch.

SETFBRANCH-NAME (NEW-VALUE OBJECT)

The name of the branch.

CURRENCY (SELF)

The currency of this invoice.

SETFCURRENCY (NEW-VALUE OBJECT)

The currency of this invoice.

DATE (OBJECT)

'YYYY-MM-DD' Date of the movement.

SETFDATE (NEW-VALUE OBJECT)

'YYYY-MM-DD' Date of the movement.

DESCRIPTION (OBJECT)

(string) A description of the movement.

SETFDESCRIPTION (NEW-VALUE OBJECT)

(string) A description of the movement.

EMAIL (OBJECT)

The fax number of the person.

SETFEMAIL (NEW-VALUE OBJECT)

The fax number of the person.

FAX (OBJECT)

The fax number of the person.

SETFFAX (NEW-VALUE OBJECT)

The fax number of the person.

FISC (OBJECT)

Whether this person is the fiscal administration.

SETFFISC (NEW-VALUE OBJECT)

Whether this person is the fiscal administration.

FISC-FISCAL-IDS (OBJECT)

(list of string) List of fiscal-id of fisc entity. An invoice issued by on of these entities is actually a tax.

SETFFISC-FISCAL-IDS (NEW-VALUE OBJECT)

(list of string) List of fiscal-id of fisc entity. An invoice issued by on of these entities is actually a tax.

FISCAL-ID (OBJECT)

The fiscal id of the owner of this invoice set.

SETFFISCAL-ID (NEW-VALUE OBJECT)

The fiscal id of the owner of this invoice set.

INVOICE-FISCAL-ID (OBJECT)

The fiscal id of the common issuer of the following invoices related to this movement.

SETFINVOICE-FISCAL-ID (NEW-VALUE OBJECT)

The fiscal id of the common issuer of the following invoices related to this movement.

INVOICE-NUMBER (OBJECT)

The invoice number.

SETFINVOICE-NUMBER (NEW-VALUE OBJECT)

The invoice number.

INVOICE-NUMBERS (OBJECT)

(list of string) The list of invoice numbers related to this entry. Note that one journal entry may relate to several invoices (grouped payment) and one invoice may relate to several movements (part payments, or corrections.

SETFINVOICE-NUMBERS (NEW-VALUE OBJECT)

(list of string) The list of invoice numbers related to this entry. Note that one journal entry may relate to several invoices (grouped payment) and one invoice may relate to several movements (part payments, or corrections.

INVOICES (SELF)

RETURN: A list of INVOICE instances related to this entry.

SETFINVOICES (NEW-VALUE OBJECT)

The list of known Invoices.

ISSUER-FISCAL-ID (OBJECT)

The fiscal ID of the issuer of this invoice.

SETFISSUER-FISCAL-ID (NEW-VALUE OBJECT)

The fiscal ID of the issuer of this invoice.

KIND (OBJECT)

(symbol) A kind of movement, for tax reporting purpose. PRESTACION-NACIONAL, PRESTACION-INTRACOMUNITARIA, IMPUESTO, INVERSION, GASTO-CORRIENTE, ADQUISICION-INTRACOMUNITARIA

SETFKIND (NEW-VALUE OBJECT)

(symbol) A kind of movement, for tax reporting purpose. PRESTACION-NACIONAL, PRESTACION-INTRACOMUNITARIA, IMPUESTO, INVERSION, GASTO-CORRIENTE, ADQUISICION-INTRACOMUNITARIA

LANGUAGE (OBJECT)

The language (two-letter code) used by this person.

SETFLANGUAGE (NEW-VALUE OBJECT)

The language (two-letter code) used by this person.

LINES (OBJECT)

(list of Invoice-Line) The line items of this invoice.

SETFLINES (NEW-VALUE OBJECT)

(list of Invoice-Line) The line items of this invoice.

NAME (OBJECT)

The name of the person.

SETFNAME (NEW-VALUE OBJECT)

The name of the person.

OBJECT-ID (OBJECT)

The user-level ID of this object.

SETFOBJECT-ID (NEW-VALUE OBJECT)

The user-level ID of this object.

PAYER-FISCAL-ID (OBJECT)

The fiscal ID of the payer of this invoice.

SETFPAYER-FISCAL-ID (NEW-VALUE OBJECT)

The fiscal ID of the payer of this invoice.

PERSONS (OBJECT)

The list of known Fiscal-Person.

SETFPERSONS (NEW-VALUE OBJECT)

The list of known Fiscal-Person.

PHONE (OBJECT)

The phone number of the person.

SETFPHONE (NEW-VALUE OBJECT)

The phone number of the person.

SORTED (OBJECT)

Indicates whether entries are sorted.

SETFSORTED (NEW-VALUE OBJECT)

Indicates whether entries are sorted.

SWIFT-CODE (OBJECT)

The swift-code of the bank.

SETFSWIFT-CODE (NEW-VALUE OBJECT)

The swift-code of the bank.

TITLE (OBJECT)

The title of this invoice.

SETFTITLE (NEW-VALUE OBJECT)

The title of this invoice.

TOTAL-HT (OBJECT)

The total excluding taxes of this invoice.

SETFTOTAL-HT (NEW-VALUE OBJECT)

The total excluding taxes of this invoice.

TOTAL-TTC (OBJECT)

The total including taxes of this invoice.

SETFTOTAL-TTC (NEW-VALUE OBJECT)

The total including taxes of this invoice.

TOTAL-VAT (OBJECT)

The total of VAT.

SETFTOTAL-VAT (NEW-VALUE OBJECT)

The total of VAT.

VAT-RATE (SELF)

RETURN: A computed VAT rate for this movement.

SETFVAT-RATE (NEW-VALUE OBJECT)

The rate of VAT for this line (0.00 <= vat-rate <= 0.50).

WEB (OBJECT)

The URL of the web site of this person.

SETFWEB (NEW-VALUE OBJECT)

The URL of the web site of this person.

Undocumented

ENTRIES (OBJECT)

SETFENTRIES (NEW-VALUE OBJECT)

YEAR (OBJECT)

SETFYEAR (NEW-VALUE OBJECT)

VARIABLE

Public

*CURRENCY-READTABLE*

The readtable used to read currencies.

*INVOICE-SET*

Current Invoice Set (instance of INVOICE-SET).

*JOURNAL*

Current Journal (instance of JOURNAL).

Private

*DEFAULT-CURRENCY*

The currency used when no prefix currency code is given to #m

*INVOICE-DIRECTORY-PATH*

The directory where the generated invoices are stored.

*INVOICE-SET-FILE-PATH*

Path to the file where invoices are stored.

*MAX-MOVEMENT-AMOUNT*

The maximum movement amount (ht or ttc, expressed in the currency of the movement (weak, I know).

*VAT-RATES*

The valid VAT rates in the country of the user.

*ZERO-AMOUNTS*

A cache of 0 amount for the various currencies used.

+LINE-CHARS+

A string containing the new-line characters.

Undocumented

*INVOICE-STRINGS*

*MOVEMENT-KINDS*

CLASS

Public

BANK-REFERENCE (OBJECT)

A bank account reference.

FISCAL-PERSON

A person (physical or moral) identified by a fiscal identification number.

INVOICE (&REST ARGS)

An invoice, either outgoing or incoming. The amounts of the invoice may be negative when it's a refund.

INVOICE-LINE

An Invoice Line.

INVOICE-SET

This class gather all the data sets about invoices and fiscal persons.

JOURNAL

An account journal.

MOVEMENT

An entry in the journal. A movement with a positive amount is a credit, while a movement with a negative amount is a debit.

PJB-OBJECT

This is a root class for my classes.

Private

AMOUNT

An amount of money.

Undocumented

DATE (OBJECT)

CONDITION

Private

Undocumented

MOVEMENT-ERROR

MULTI-CURRENCY-ERROR

CONSTANT

Private

+SECONDS-IN-A-DAY+

Number of seconds in a day.