2017 © Pedro Peláez
 

symfony-bundle invoice-painter-bundle

Symfony2 Bundle to help render PDF Invoices

image

realtyhub/invoice-painter-bundle

Symfony2 Bundle to help render PDF Invoices

  • Tuesday, April 24, 2018
  • by realtyhub
  • Repository
  • 1 Watchers
  • 6 Stars
  • 1,470 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Freelance Banner, (*1)

Invoice Painter Bundle

This Symfony2 bundle has the simple purpose of helping your application generate PDF invoices. It doesn't concern itself with logic relating to your pricing or payment system, this work is still performed by your application., (*2)

Installation and configuration

Composer.json, (*3)

``` json { ... "require": { "realtyhub/invoice-painter-bundle": "dev-master" } }, (*4)


AppKernel.php ``` php <?php public function registerBundles() { $bundles = array( // ... new Realtyhub\InvoicePainterBundle\RealtyhubInvoicePainterBundle(), ); }

config.yml, (*5)

``` yml realtyhub_invoice_painter: currency_symbol: "dollar" #supported options 'dollar', 'pound', 'euro', 'yen' tax_short_name: "TAX" #Can be any string you like, such as "VAT" or "GST", (*6)




# Basic Usage ``` php //Inside controller file use Realtyhub\InvoicePainterBundle\Entity\InvoicePainterDataContainer; use Realtyhub\InvoicePainterBundle\Entity\InvoicePainterItem; class DefaultController extends Controller { public function invoiceTestAction() { $invoiceData = new InvoicePainterDataContainer(); $invoiceData->setInvoiceDate( new \DateTime() ); $invoiceData->setTaxNumber( '200 122 492' ); $invoiceData->setInvoiceNumber( 'INV00034' ); $invoiceData->addClientNameLine('Your clients name'); $invoiceData->addClientNameLine('or clients business name'); $invoiceData->addClientAddressLine('89 Green Road'); $invoiceData->addClientAddressLine('Melbourne, VIC'); $invoiceData->addClientAddressLine('Australia'); $invoiceData->addClientAddressLine('3000'); $invoiceData->addCompanyNameLine('Your Company Name'); $invoiceData->addCompanyNameLine('Another line of your company name'); $invoiceData->addCompanyAddressLine('920 Smith Street'); $invoiceData->addCompanyAddressLine('Sydney, NSW'); $invoiceData->addCompanyAddressLine('Australia'); $invoiceData->addCompanyAddressLine('2000'); $invoiceData->addInvoiceItem( InvoicePainterItem::createFromParams(1499, 0.2, 'Dell Laptop', new \DateTime() ) ); $invoiceData->addInvoiceItem( InvoicePainterItem::createFromParams(119, 0.2, 'Canon Computer Printer', new \DateTime() ) ); $invoiceData->addInvoiceItem( InvoicePainterItem::createFromParams(6, 0.2, 'A4 printer paper', new \DateTime() ) ); return $this->forward('realtyhub_invoice_painter:paintAction', array('invoiceData' => $invoiceData)); }

Alternative technique using InvoicePainterItemInterface

You may already have an entity that directly relates to an invoice item. For example, your entity may already contain the Sale price, the tax rate, description and sale date., (*7)

In this case you can make this entity implement InvoicePainterItemInterface, (*8)

//Some entity file
use Realtyhub\InvoicePainterBundle\Entity\InvoicePainterItemInterface;

/**
 * @ORM\Table(name="sales_history")
 * @ORM\Entity()
 */
class SalesHistory implements InvoicePainterItemInterface
{

    /**
     * @ORM\Column(name="description", type="string", length=255)
     */
    private $description;

    /**
     * @ORM\Column(name="sale_at", type="datetime")
     */
    private $saleAt;

    /**
     * @ORM\Column(name="price_ex_tax", type="float")
     */
    private $priceExTax;

    /**
     * @ORM\Column(name="tax_rate", type="float")
     */
    private $taxRate;

    //Implement methods from InvoicePainterItemInterface
    public function getInvoicePainterAmountEx()
    {
         return $this->priceExTax;
    }

    public function getInvoicePainterTaxRate()
    {
         return $this->taxRate;
    }

    public function getInvoicePainterDate()
    {
         return $this->saleAt;
    }

    public function getInvoicePainterDescription()
    {
         return $this->description;
    }

//changes required in the controller action


$salesHistory = $salesHistoryRepository->findAll();

foreach ($salesHistory as $sale)
{
    // $sale will be instance of SalesHistory 
    $invoiceData->addInvoiceItem( InvoicePainterItem::createFromInterface($sale) ); //instead of $invoiceData->addInvoiceItem( InvoicePainterItem::createFromParams(1499, 0.2, 'Dell Laptop', new \DateTime() ) );
}

The Versions

24/04 2018

dev-master

9999999-dev https://github.com/realtyhub/InvoicePainterBundle

Symfony2 Bundle to help render PDF Invoices

  Sources   Download

The Requires

 

by Samual Anthony