yeknava/simple-invoice

simple invoice package for laravel

0.2 2020-07-29 19:49 UTC

This package is auto-updated.

Last update: 2024-04-29 04:27:17 UTC


README

Laravel Simple Invoice Package.

Installation

Use the package manager composer to install simple invoice package.

composer require yeknava/simple-invoice

Usage

Run this command in your terminal:

php artisan vendor:publish

Add Biller trait to payers models and Add InvoiceOwner trait to payee models if there is any.

<?php

use Yeknava\SimpleInvoice\Biller;

class User extends Model {
    use Biller;
}
<?php

use Yeknava\SimpleInvoice\InvoiceOwner;

class OwnerModel extends Model {
    use InvoiceOwner;
}
$user = User::find(1);

$user1 = (new UserModel([]));
$user1->save();
$user2 = (new OwnerModel([]));
$user2->save();

$invoice = $user1->newBill('bill title');
$invoice->setOwner($user2);
$invoice->addItem((new InvoiceItem(1000, 'item1'))
    ->setTax(100)
    ->setItem(ItemModel::find(1))
    ->setQuantity(5)
    ->setShippingPrice(100)
    ->setDiscountInPercent(10));
$invoice->addItem((new InvoiceItem(1000, 'item2'))
    ->setTax(100)
    ->setQuantity(5)
    ->setShippingPrice(100)
    ->setDiscountInPercent(10));

$generatedInvoice = $invoice->setExpiredDate(Carbon::now())->generate();
try {
    $generatedInvoice->paid();
} catch (ExpiredInvoiceException $e) {
}

$invoice = $invoice->setExpiredDate(Carbon::now()->addDay())->generate();
$invoice = $invoice->paid();

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT