twm/laravel-invoice

This is my package laravel-invoice

1.0 2023-06-08 12:38 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require twm/laravel-invoice

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-invoice-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-invoice-config"

This is the contents of the published config file:

return [
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-invoice-views"

Usage

// You have to create an array with pairs key-value with invoice table columns 

$example = [
   'client_id' => null,
        'customer_name' => $faker->company(),
        'customer_reg_com_nr' => $faker->word(),
        'customer_cui' => $faker->word(),
        'customer_address' => $faker->address(),
        'customer_iban' => Str::random(10),
        'customer_bank' => $faker->word(),
        'customer_county' => 'Bucuresti',
        'provider_name' => $faker->company(),
        'provider_reg_com_nr' => $faker->word(),
        'provider_cui' => $faker->word(),
        'provider_address' => $faker->address(),
        'provider_iban' => Str::random(10),
        'provider_bank' => $faker->word(),
        'provider_capital' => '200 RON',
        'cota' => 19,
        'termen_de_plata' => '2023-05-31',
        'payment_url' => 'www.example.com' //optional
];

/** For each line of invoice lines you have to create a collection with lines like this */

// Initialize an empty collection

$linesCollection = collect([]);

foreach($lines as $line) {
   $line = (new Line())->name('Product name')
                        ->unit('buc')
                        ->quantity(4)
                        ->price(100)
                        ->pret_fara_tva(19)
                        ->valoare_fara_tva(19)
                        ->valoare_tva(19);
   // If you want to create a line with discount you have to use the discount method after price method
                        '.....'
                        ->price(100)
                        ->discount(100)
                        '.....'
            
   $linesCollection->push($line);
}

/** To generate invoice you have to use this line */

$invoice = InvoiceGenerator::init()->make($example)->lines($linesCollection);

/** first argument is the name of invoice and the second is the disk you want to save the invoice */
$invoice->generate('Invoice_name.pdf','local');


/** If you want to generate an existing invoice use this */

$inv = Invoice::first();

GenerateExisting::generate($inv,'Invoice_name.pdf');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.