PHP code example of tomatophp / filament-invoices

1. Go to this page and download the library: Download tomatophp/filament-invoices 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/ */

    

tomatophp / filament-invoices example snippets


->plugin(\TomatoPHP\FilamentInvoices\FilamentInvoicesPlugin::make())

->plugin(
    \TomatoPHP\FilamentInvoices\FilamentInvoicesPlugin::make()
        ->useSettingsHub()
)

use TomatoPHP\FilamentInvoices\Facades\FilamentInvoices;
use TomatoPHP\FilamentInvoices\Services\Contracts\InvoiceFor;
use TomatoPHP\FilamentInvoices\Services\Contracts\InvoiceFrom;

public function boot()
{
    FilamentInvoices::registerFor([
        InvoiceFor::make(Account::class)
            ->label('Account')
    ]);
    FilamentInvoices::registerFrom([
        InvoiceFrom::make(Company::class)
            ->label('Company')
    ]);
}

use TomatoPHP\FilamentInvoices\Services\Templates\TemplateFactory;
use TomatoPHP\FilamentInvoices\Contracts\InvoiceTemplateInterface;

// In your service provider boot method
TemplateFactory::register('my-custom', MyCustomTemplate::class);

use TomatoPHP\FilamentInvoices\Contracts\InvoiceTemplateInterface;
use TomatoPHP\FilamentInvoices\Services\Templates\AbstractTemplate;

class MyCustomTemplate extends AbstractTemplate
{
    public function getName(): string
    {
        return 'my-custom';
    }

    public function getLabel(): string
    {
        return 'My Custom Template';
    }

    public function getDescription(): string
    {
        return 'A custom invoice template';
    }

    public function getViewPath(): string
    {
        return 'my-package::templates.custom';
    }
}

use TomatoPHP\FilamentInvoices\Services\PdfGenerator;

$pdfGenerator = app(PdfGenerator::class);

// Generate PDF content
$pdfContent = $pdfGenerator->generate($invoice, 'modern');

// Stream to browser
return $pdfGenerator->stream($invoice, 'classic');

// Download file
return $pdfGenerator->download($invoice, 'professional');

use TomatoPHP\FilamentInvoices\Mail\InvoiceMail;
use Illuminate\Support\Facades\Mail;

Mail::to('[email protected]')->send(new InvoiceMail(
    invoice: $invoice,
    template: 'modern',
    cc: '[email protected]',
    subject: 'Your Invoice #{uuid}',
    body: 'Dear {customer_name}, please find your invoice attached.'
));

\TomatoPHP\FilamentInvoices\Facades\FilamentInvoices::create()
    ->for(\App\Models\Account::find(1))
    ->from(\App\Models\Account::find(2))
    ->dueDate(now()->addDays(7))
    ->date(now())
    ->items([
        \TomatoPHP\FilamentInvoices\Services\Contracts\InvoiceItem::make('Item 1')
            ->description('Description 1')
            ->qty(2)
            ->price(100),
        \TomatoPHP\FilamentInvoices\Services\Contracts\InvoiceItem::make('Item 2')
            ->description('Description 2')
            ->qty(1)
            ->discount(10)
            ->vat(10)
            ->price(200),
    ])->save();            
bash
php artisan filament-invoices:install
bash
php artisan vendor:publish --tag="filament-invoices-settings-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-invoices-config"
bash
php artisan vendor:publish --tag="filament-invoices-views"
bash
php artisan vendor:publish --tag="filament-invoices-lang"
bash
php artisan vendor:publish --tag="filament-invoices-migrations"