DocumentTypes::Invoice

A gem that adds invoice document type support to plugandwork application.

Installation

Add this line to your application's Gemfile:

gem 'document_types-invoice'

And then execute:

$ bundle install

Prerequisites

This gem requires the following infrastructure in your application:

  1. A DocumentTypes::Registry class for document type registration
  2. A DocumentTypable concern included in your Doc model
  3. Mongoid as the database ORM

Features

  • Invoice document type with specific fields (invoice number, dates, amounts, etc.)
  • Automatic detection of invoices from PDF and XML files
  • Support for structured invoice formats (Factur-X, UBL, CII)
  • Invoice-specific search functionality
  • Business logic methods for invoice processing

Usage

Search for invoices

# Search invoices by amount
invoices = DocumentTypes::InvoiceService.search(min_amount: 1000, max_amount: 5000)

# Get unpaid invoices
unpaid = DocumentTypes::InvoiceService.unpaid_invoices

# Get overdue invoices
overdue = DocumentTypes::InvoiceService.overdue_invoices

Convert a document to an invoice

# Detect if a document is an invoice
if DocumentTypes::InvoiceRecord.detect(my_doc)
  # Process as an invoice
  invoice = my_doc.as_invoice
  puts "Invoice: #{invoice.invoice_number}, Amount: #{invoice.total_amount} #{invoice.currency}"
end

Get invoice statistics

# Get statistics for the current month
stats = DocumentTypes::InvoiceService.stats_for_current_month

puts "Total: #{stats[:total]}"
puts "Average: #{stats[:average]}"
puts "Count: #{stats[:count]}"

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.