Skip to content

omnizya/legman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@omnizya/legman

A modern, generic, customizable, and plug-and-play document generation framework with full internationalization (i18n) support and Moroccan legal compliance.

Features

  • Plugin Architecture - Easily extend with custom document types
  • i18n Support - Multi-language support (English, French, Arabic)
  • Generic Framework - Generate any type of document (invoices, bills, receipts, etc.)
  • Moroccan Compliance - Full support for Moroccan laws and auto-entrepreneur regulations
  • Configuration Management - Centralized, factory-based configuration
  • Middleware & Hooks - Custom validators and transformers
  • Multiple Output Formats - PDF, HTML (easily extensible)
  • Backward Compatible - Legacy API still works

Installation

npm install @omnizya/legman

Quick Start

Basic Usage

import DocumentFactory from '@omnizya/legman'
import { PDFDocumentGenerator } from '@omnizya/legman'

// Create factory
const factory = new DocumentFactory()
await factory.initialize('en') // English

// Setup company
factory.setCompanyInfo({
  name: 'My Company',
  address: '123 Business St',
  city: 'New York',
  phone: '+1 (555) 123-4567',
  email: 'info@mycompany.com'
})

// Create generator
const generator = factory.createGenerator('pdf')

// Generate PDF
const pdfBuffer = await generator.generateBuffer({
  OrderNumber: 'INV-001',
  IssueDate: new Date(),
  Items: [
    { Description: 'Service', PriceExcludingVat: 1000 }
  ],
  Currency: 'MAD',
  PriceExcludingVat: 1000,
  VatAmount: 200,
  TotalPrice: 1200
})

Moroccan Auto-Entrepreneur Setup

import DocumentFactory from '@omnizya/legman'

// Enable Moroccan compliance
const factory = new DocumentFactory()
await factory.initialize('ar') // Arabic
factory.enableMoroccoCompliance()
factory.enableAutoEntrepreneur({
  activityType: 'services' // 'services' (1%), 'commerce' (0.5%), 'artisana' (0.5%)
})

// For high-value invoices (>80,000 MAD for single client), 30% withholding tax applies automatically

// Setup Moroccan company info
factory.setCompanyInfo({
  name: 'شركتي',
  address: '123 شارع الأعمال',
  city: 'الرباط',
  ice: '123456789',
  rc: 'RC12345',
  patente: 'PAT123',
  cnss: 'CNSS123'
})

// Create auto-entrepreneur invoice generator
const generator = factory.createGenerator('pdf', {
  documentType: 'autoEntrepreneurInvoice'
})

// Generate compliant invoice
const pdfBuffer = await generator.generateBuffer({
  OrderNumber: 'AE-INV-001',
  IssueDate: new Date(),
  Items: [
    { Description: 'خدمة', PriceExcludingVat: 1000 }
  ],
  PriceExcludingVat: 1000
})

Core Concepts

DocumentFactory

The main entry point for document generation. Manages everything centrally.

const factory = new DocumentFactory()

// Initialize with language
await factory.initialize('en')

// Configure globally
factory.setConfig({
  language: 'en',
  dateFormat: 'L',
  defaultCurrency: 'MAD'
})

// Set company info
factory.setCompanyInfo({
  name: 'Your Company',
  address: '...',
  // ... other fields
})

// Change language at runtime
factory.setLanguage('fr')

Plugin System

Register and use plugins for different document types.

// Register a custom plugin
factory.registerPlugin('custom', {
  name: 'Custom Document',
  type: 'generator',
  description: 'My custom document type'
})

// Use it
const generator = factory.createGenerator('custom')

Moroccan Compliance

Full support for Moroccan business regulations:

  • Auto-Entrepreneur Invoices: Simplified invoices for self-employed individuals
  • Tax Calculations: Automatic tax calculation based on activity type:
    • Services: 1% tax rate
    • Commerce/Artisana: 0.5% tax rate
    • High-value invoices (>80,000 MAD for single client): 30% withholding tax (RAS)
  • Legal Requirements: Compliance with Moroccan invoice format requirements
  • Arabic Support: Full Arabic language support for Moroccan documents

Supported Document Types

  • invoice - Standard invoices
  • bill - Bills
  • receipt - Receipts
  • autoEntrepreneurInvoice - Moroccan auto-entrepreneur invoices

Supported Languages

  • English (en)
  • French (fr)
  • Arabic (ar)

API Reference

DocumentFactory

  • initialize(language) - Initialize with language
  • setCompanyInfo(info) - Set company information
  • setConfig(config) - Set global configuration
  • setLanguage(language) - Change language
  • createGenerator(type, options) - Create document generator
  • enableMoroccoCompliance() - Enable Moroccan compliance mode
  • enableAutoEntrepreneur(options) - Enable auto-entrepreneur mode

Generators

  • generateBuffer(content, options) - Generate as buffer
  • generateDownload(content, filename, options) - Download file
  • generateViewer(content, options) - Open in viewer
  • generatePrint(content, filename, options) - Print document

Contributing

Contributions are welcome! Please see our Contributing Guide for details.

License

MIT License - see LICENSE for details.

Support

For support, please contact us at support@omnizya.com or create an issue on GitHub.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors