I have been using the Invoice 6.x-1.x module for quite some time for personal invoicing use. It works great for my purposes, but I think there is potential to bring it to a new level, in terms of it's flexibility as a general-purpose Invoicing solution.

I would like to put forth a proposal for a 7.x-2.x branch of this module. I have a number of goals in mind with this idea:

  • Instead of creating an Invoice node type, a new Invoice entity type would be provided, leveraging Drupal 7's entity system and the Entity API module.
  • Change the way that items are managed. Perhaps add another entity type for "Invoice Line Item", and a special form for managing them on an invoice. Also, some kind of hook that allows other modules to add line items or implement their own types.
  • Change the way that Customers are referenced on the Invoice, to make it more compatible with other modules that also use the concept of "Customer" like Ubercart/Commerce. Perhaps it could just be a field that references other Customer entities.
  • Perhaps work with the maintainers of other existing projects (Commerce Invoice, Commerce PDF Invoice) to create a general purpose Invoice module that those modules could leverage, instead of reinventing the wheel in each.

The overall goal would be to create an Invoice module that can be used by other modules. It can provide an API for generating invoices, and hooks to allow other modules to provide their own data and functionality.

I am somewhat interested in starting fresh with this branch, but reusing existing Invoice module code where possible. Providing an upgrade path from 1.x would be a good idea, but maybe it isn't necessary. Perhaps this should be considered a new project altogether, but using the same "Invoice" project namespace. Just thinking out loud....

Would you be interested in working together on this?

Comments

pietervogelaar’s picture

Thanks for your proposal. I like your ideas and it would definitely be a nice direction to go with the module.

Unfortunately I have way to less time to help actively building this all at the moment. But if you are really serious about building a very large part of the module than I would surely consider creating a branch 2.x-dev for it.

Let me know!

Greetings,
Pieter

m.stenta’s picture

I would love to take the lead on development, if you're ok with it. And I'm open to any ideas or preferences you may have in the matter as well.

It may be a little while before I can dedicate some real time to it, but I've been working on an Accounting suite of modules for Drupal (currently a distribution sandbox that mainly uses my Ledger module), so an Invoice component will certainly be necessary sooner or later.

Would you like to get together in an IRC chat sometime to talk about it?

pietervogelaar’s picture

Okay perfect! I added you as maintainer of this module. I will send you a personal message for further details.

Pieter

m.stenta’s picture

Thanks P.Vogelaar! I will use this issue to flesh out the ideas of this proposal.

Noe_’s picture

I might be interested too, and able to do some work.
So if you make a new git branch I can provide you with patches.

Just my .2c

m.stenta’s picture

Here are my initial thoughts on the 7.x-2.x branch of this module. Let me know what you think...

First, this branch will be a rewrite from the ground up. As such, it will not maintain backwards compatibility with the 7.x-1.x branch during development. Once the main pieces are in place, we can write an upgrade path from 1.x -> 2.x (if needed).

Architecture

The project will be a collection of modules, organized by their function. Similar to the Commerce and Ledger modules, there will be a separation between "model" and UI components, to help organize and compartmentalize functions.

The entity types that it would provide are: "Invoices" and "Invoice Items". Invoices contain a list of Invoice Items, as well as any other fields that the entity needs.

Invoice ownership

Each Invoice would be "owned" by a Drupal user (whoever creates it). The Invoice module would provide each Drupal user the ability to customize their address information, logo, etc, which would be displayed in the viewed invoice.

Customers

Each invoice will need to have a customer name and address information associated with it, so that it can be addressed properly to the recipient. In the 1.x branches of this module, a separate "customer" entity (in essence) is provided, however I think there's a better way to do it...

There are a number of Drupal modules that already provide some kind of "customer" record, so maybe we can find a way to provide integration, rather than implement our own. This is tricky, though, because it requires mapping information from an arbitrary entity type to the fields that we need to display in the Invoice. Perhaps we can add configuration to the Invoice module that allows site builders to configure which entity is their "customer" entity, and then allow properties of that entity type to be mapped to placeholders in the Invoice template. I'm open to ideas on this.

Invoice templates

Initially, it might be easiest to just provide a single basic "view" page that renders a full invoice in a generic fashion.

I like the idea of having multiple invoice templates to choose from, but in lieu of the "Invoice ownership" stuff above, it raises questions about who "owns" the templates. Are they site-wide? Or can each user have their own? Just things to think about... I think we need to discuss this more to see what's necessary.

Also, in the future, perhaps we could provide individual invoice components as panel panes so that Invoice layouts could be customized using Panels.

Other considerations

VAT and other taxes

I think tax support should be provided by separate modules (ie: invoice_vat, invoice_sales_tax, etc), so that site builders have the option of including one, if they need it. Such modules could hook into the Invoice and Invoice Item modules to provide support for tax calculation and UI.

PDF generation

Can we offload the PDF handling (as well as print/fax versions) to the Print module: http://drupal.org/project/print ?

First steps...

I think we can get up and running pretty quickly with this by using similar existing modules as a starting point. The Ledger module does a lot of the same things we'll be doing, so we can save time by copying code and just altering what we need to. For example, the Invoice and Invoice Item entity types would share a lot of similarity to the Transaction and Account Entry entity types in Ledger. Both use the concept of a parent entity that can have multiple child entities.

We can start by creating the Invoice and Invoice item modules (and their UI counterpart modules), which will provide all the functionality and UI necessary for creating and managing Invoices and their items. In addition to providing the necessary entity API functions, they would provide forms for editing entities, a page for viewing an entity, and default Views for admin management lists.

From there we can figure out what needs to happen next... whether it's taxes/pdf support, or what. I'm open to ideas on the best way to go about it. What do you think?

Here is a quick brainstorm of the initial submodules that would need to be written to start with:

Invoice

-Provides an "Invoice" entity type and all core invoice hooks and functions.
-Depends on Invoice Item.

Invoice Item

-Provides an "Invoice Item" entity type.

Invoice UI

-Provides user interface elements for managing Invoice entities (ie: forms and Views).
-Depends on Invoice.

Invoice Item UI

-Provides UI for managing Invoice Items (ie: form element).
-Depends on Invoice item.

Open to all feedback and ideas!

mxh’s picture

What would be the benefit when the invoice is an entity, not a node?

What about a price field like the one of Drupal Commerce?

m.stenta’s picture

The benefit of making an Invoice entity type is a better overall data architecture. While it is definitely possible to use the Node architecture to represent Invoices, it comes with a lot of other baggage that isn't necessary. By creating an Invoice type, we can be more specific about what an Invoice is, how it works, and what people can do with it.

The Commerce module provides a bunch of entity types: Products, Orders, Customer profiles, etc (http://www.drupalcommerce.org/developer-guide/core-architecture/entities). The decision to make these into entity types instead of nodes makes sense, because each of them has specific goals in mind. The same is true with Invoices.

"Nodes" in Drupal 7+ are generally used to refer to "content". That's a pretty general idea in itself, but it comes with a lot of assumptions. They have a published/unpublished status, and can be "promoted to front page" for example, among many other node-specific things. These are functions that make sense for content like pages, blog posts, and other public-facing stuff, but when you're dealing with items that are more behind-the-scenes, like orders or invoices, you don't necessary need or want all of that. With the entity system, you can still achieve all of that if you want, using Fields and Views, but it isn't forced upon you. You can start with a more lightweight system and build from there.

More info about entities in Drupal 7: https://drupal.org/node/1261744

Regarding the price field in Commerce: could you go into more detail about what you mean?

mxh’s picture

I see.
Comerce Price field: Sorry, I just wanted to know your opinion about it, if it would be also suitable for the "unit price" field in invoice entity type (and maye for the total amount).

Unfortunately I didn't find a "money field" or similar for D7 and don't know what to use for field with price information. Would even an own development be neccessary - you mentioned a line item for invoices, would this include pricing?

I'm interested in this module because I'm looking for a invoice management solution in my distribution Biz To Web, but as I see some active major issues here and the maintainer isn't very active on this, the 7.x-1.x version is not satisfactory - So I'm thinking about to start an own invoice management using a node type "invoice", but I'd like to have my distribution working with good modules and no "lonely islands" whre later the distribution becomes unflexible.

I see you're also interested on this module, maybe we could work together starting a new project or to start 7.x-2.x?

I think what really is missing in the Drupal world is a general-purpose invoice module, including a tax calculation but which is independent from "Shop" modules. I hope you understand what I mean.

m.stenta’s picture

I agree we should take a look around to see how other modules are dealing with prices, and I have some ideas there too (ie: #1125706: Price Implementation for Commerce 2.x). Generally speaking, though, it would be best to make sure that we minimize dependency as much as possible. I think it will be great to create integration between Commerce and Invoice... it would simplify the responsibilities of both... but they should also be able to operate independently.

To answer your question: yea, I think the "Invoice Item" or "Invoice Line Item" (whatever we call it), would be responsible for storing price information of some kind (and probably quantity too). That still needs some more definition. What kinds of information would we want to store in each item? The Invoice module currently stores line items with the following fields:

  • Invoice item id
  • Description
  • Quantity
  • Unit cost
  • VAT
  • Weight
  • Invoice id
  • User id
  • Creation date

We probably want many of the same. VAT can be added by another module, so that we don't make assumptions about tax requirements (see my comment #6 above). I don't know if we need User id or Creation date, because those would be set on the Invoice itself. The same thing goes for Weight, I think, because the Invoice itself will be managing references to Invoice items, so it will also be storing the sequence that they are arranged in.

So that just leaves:

  • Invoice item id
  • Invoice id
  • Description
  • Quantity
  • Cost

Are there others that would be needed? All of this is still up for discussion, of course, I'm just proposing an initial path.

mxh’s picture

Generally speaking, though, it would be best to make sure that we minimize dependency as much as possible.

I agree, but at the moment there are some problems which prohibit this goal:

  • Commerce module requires to enable Product, Product pricing, Rules and other modules to be enabled if you want to use the Tax module of Commerce. The Tax module itself should be completely independent and should be usable by Invoice and Commerce module. I see in #6 you want an own Tax module? (like invoice_tax..?) But wouldn't this mean that Commerce and Invoice are not really interacting, because you would have to configure a tax module for Invoice and for Commerce then.
  • As I see in #1125706: Price Implementation for Commerce 2.x the optimum price field implementation is far away.
  • Currency is only configurable when Commerce and Commerce UI is enabled. Why not separate the currency from Commerce? I know you don't maintain Commerce, but I just write down my thoughts here to start off.

Important for me in an invoice is following:

- Invoice item id (maybe iid?)
- Invoice Id (similar to title of nodes)
- Company information (Needed Information: return address, bank information, VAT ID number, etc.) -- Maybe extra module for this, which extends website information page with configurable company informations.
- Customer address, customer salutation ("Dear Mrs. XY") -- Maybe Customer module of Commerce.
- Invoice line item (should be also an entity), containing position (as you already said, by system), description (long text), quanity (float or decimal?), Unit price (Price field?), discount information (but also additional charge, so it should be managed with a + / prefix), line amount (Price field? Computed field?).
- Total invoice amount with and / or without VAT (Price / Computed field?), this should be stored into the database to make it also work with Finder module, for example.
- VAT information ( "Price includes tax" / + tax amount: $XX ).

It's late sorry, I will post a better understanding comment next time.

mxh’s picture

Another proposal for 7.x-2.x: To start off, we could develop a completely independent module, which neither uses Price field nor Tax Module of Commerce and also not its Currency feature. By meaning: No Commerce dependency.
I think it would first be enough to simply define the entity type. The admin could manage simple currency, tax and price settings in the entity of type "invoice" edit form, like in
admin/structure/invoices/manage/b2c, where b2c is an invoice type.

During the development time we can talk with the commerce maintainers about making their modules and features easier accessible, and then either develop an additional submodule "Commerce integration" or just start a new 7.x-3.x branch.

What do you think about it?

slashrsm’s picture

m.stenta’s picture

@hauptm: I agree 100% that there should be no dependency on Commerce. Ideally, the Invoice module and the Commerce module could be used together. Perhaps that can be accomplished with Rules, instead of any integration modules (ie: when an order is created, create an invoice, and keep it's line items in sync with the order's).

@slashrsm: I also agree that the 2.x branch should use Drupal's theme system for templating.

pietervogelaar’s picture

Draggable invoice items would be a nice feature: http://drupal.org/node/349459

cweagans’s picture

Regarding 1603136, I also think it's really important to also use print module for the printable invoices, rather than rolling your own solution. I consider that a bug that really ought to be fixed in the 1.x branch as well, but I guess that's not going to happen.

Marko B’s picture

1. Have some title for each invoice/short desc. for a display on invoice list. Currently I have one client with several inv. and then i dont know which is for which and some desc. would help to sort this.
2.Full views integration so the paid/unpaid switch is there also.
3. Permission to see only own invoices, currently everbody can see anybodys invoice, right? and this should be granulated, maybe best as default "node modul" permission set.

pietervogelaar’s picture

I really love to see REST API functionality again in version 2 that the 1.1 version has.

CocoLeBo’s picture

Hello, we have just started looking at Drupal as an alternative to our own "home grown" solution.

I've also, just started looking at this module, and hope you don't mind a question (or possible feature request) - can this module (Invoice) create:

  • Proposals
  • Statement of work (SOW) or [Scope of work]

We currently generate proposals prior to doing the work, and then an Invoice upon completion, so a "Proposal" would be a nice feature - with pricing, etc....

We also generate a Statement of Work (SOW) (now we actually create the SOW & Proposal at the same time, the SOW just contains no pricing information - it is specifically designed to provide the necessary scope of the work to be completed by either internal or external parties.

Thank you!
Coco LeBo