PHP code example of budgetinvoice / easyinvoice

1. Go to this page and download the library: Download budgetinvoice/easyinvoice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

budgetinvoice / easyinvoice example snippets




use BudgetInvoice\EasyInvoice

// Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "product": [
        "quantity" => 2,
        "description" => "Product 1",
        "tax-rate" => 6,
        "price" => 33.87
    ]
];

// Sample code to test the library
$invoice = EasyInvoice::create($invoiceData);

// The invoice['pdf'] variable wil contain a base64 PDF string
echo $invoice['pdf'];

// Save the file locally as PDF
$fileName = 'invoice';
EasyInvoice::save($invoice['pdf'], $fileName);



use BudgetInvoice\EasyInvoice

//Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production    
    "images" => [
        // The logo on top of your invoice
        "logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
        // The invoice background
        "background" => "https://public.easyinvoice.cloud/img/watermark-draft.jpg"
    ],
    // Your own data
    "sender" => [
        "company" => "Sample Corp",
        "address" => "Sample Street 123",
        "zip" => "1234 AB",
        "city" => "Sampletown",
        "country" => "Samplecountry"
        //"custom1" => "custom value 1",
        //"custom2" => "custom value 2",
        //"custom3" => "custom value 3"
    ],
    // Your recipient
    "client" => [
        "company" => "Client Corp",
        "address" => "Clientstreet 456",
        "zip" => "4567 CD",
        "city" => "Clientcity",
        "country" => "Clientcountry"
        // "custom1" => "custom value 1",
        // "custom2" => "custom value 2",
        // "custom3" => "custom value 3"
    ],
    "information" => [
        // Invoice number
        "number" => "2021.0001",
        // Invoice data
        "date" => "12-12-2021",
        // Invoice due date
        "dueDate" => "31-12-2021"
    ],
    // The products you would like to see on your invoice
    // Total values are being calculated automatically
    "products" => [
        [
            "quantity" => 2,
            "description" => "Product 1",
            "taxRate" => 6,
            "price" => 33.87
        ],
        [
            "quantity" => 4.1,
            "description" => "Product 2",
            "taxRate" => 6,
            "price" => 12.34
        ],
        [
            "quantity" => 4.5678,
            "description" => "Product 3",
            "taxRate" => 21,
            "price" => 6324.453456
        ]
    ],
    // The message you would like to display on the bottom of your invoice
    "bottomNotice" => "Kindly pay your invoice within 15 days.",
    // Settings to customize your invoice
    "settings" => [
        "currency" => "USD", // See documentation 'Locales and Currency' for more info. Leave empty for no currency.
        // "locale" => "nl-NL", // Defaults to en-US, used for number formatting (See documentation 'Locales and Currency')        
        // "marginTop" => 25, // Defaults to '25'
        // "marginRight" => 25, // Defaults to '25'
        // "marginLeft" => 25, // Defaults to '25'
        // "marginBottom" => 25, // Defaults to '25'
        // "format" => "A4", // Defaults to A4, options => A3, A4, A5, Legal, Letter, Tabloid
        // "height" => "1000px", // allowed units: mm, cm, in, px
        // "width" => "500px", // allowed units: mm, cm, in, px
        // "orientation" => "landscape" // portrait or landscape, defaults to portrait
    ],
    // Translate your invoice to your preferred language
    "translate" => [
        // "invoice" => "FACTUUR",  // Default to 'INVOICE'
        // "number" => "Nummer", // Defaults to 'Number'
        // "date" => "Datum", // Default to 'Date'
        // "dueDate" => "Verloopdatum", // Defaults to 'Due Date'
        // "subtotal" => "Subtotaal", // Defaults to 'Subtotal'
        // "products" => "Producten", // Defaults to 'Products'
        // "quantity" => "Aantal", // Default to 'Quantity'
        // "price" => "Prijs", // Defaults to 'Price'
        // "productTotal" => "Totaal", // Defaults to 'Total'
        // "total" => "Totaal" // Defaults to 'Total',
        // "taxNotation" => "btw", // Defaults to 'vat'
    ],
    
    // Customize enables you to provide your own templates
    // Please review the documentation for instructions and examples
    //    "customize" => [
        //  "template" => base64_encode("<p>Hello World</p>"); // Must be base64 encoded html 
    //    ],
];

//Sample code to test the library
$invoice = EasyInvoice::create($invoiceData);

//The invoice object wil contain a base64 PDF string
echo $invoice['pdf'];

// Save the file locally as PDF
$fileName = 'invoice';
EasyInvoice::save($invoice['pdf'], $fileName);



use BudgetInvoice\EasyInvoice

// Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "product": [
        "quantity" => 2,
        "description" => "Product 1",
        "tax-rate" => 6,
        "price" => 33.87
    ]
];

try {
   // Sample code to test the library
   $invoice = EasyInvoice::create($invoiceData);
   
   // The invoice['pdf'] variable wil contain a base64 PDF string
   echo $invoice['pdf'];
   
   // Save the file locally as PDF
   $fileName = 'invoice';
   EasyInvoice::save($invoice['pdf'], $fileName);
} catch (Exception $e){
    echo $e->getMessage();
}

//E.g. for Germany, prices would look like 123.456,78 €
$data = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "settings" => [
        "locale" => "de-DE", 
        "currency" => "EUR"
    ]
];

//E.g. for US, prices would look like $123,456.78
$data = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "settings" => [
        "locale" => "en-US",
        "currency" => "USD"
    ]
];

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "images" => [
        "logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
        "background" => "https://public.easyinvoice.cloud/img/watermark_draft.jpg"
    ]
];

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    //Note: Sample base64 string
    //Please use the link below to convert your image to base64
    "images":[  
        "logo" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
        "background" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
    ] 
];

// You are able to provide your own html template
$html = "<p>Hello world! This is invoice number %number%</p>";

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "customize" => [
        "template" => base64_encode($html) // Your template must be base64 encoded
    ],
    "information" => [
        "number" => "2022.0001"
    ]
];

$invoice = EasyInvoice::create($invoiceData);
// This will return a pdf with the following content
// Hello world! This is invoice number 2022.0001