neptunesoftware/laravel-invoice

使用Laravel Eloquent轻松生成发票

2.0.3 2020-04-21 09:30 UTC

README

PHP Composer Latest Version on Packagist Software License Total Downloads Code Coverage

此包已更改、更新和重新分发。要使用原始分发,请参阅sandervanhooft/laravel-invoicable存储库。

重要

此分支将由@neptunesoftware维护,且与原始存储库不兼容。

为Laravel提供轻松的发票创建功能。与Laravel Cashier不同,此包与支付网关无关。

有何不同?

要跟踪更改,请参阅变更日志文件。

结构

.
├── config              # Configuration file
├── database            # Database files
│   └── migrations      
├── resources           # Resource files 
│   └── views           
├── src                 # Soruce files
│   ├── Interfaces      
│   ├── Models          
│   ├── Providers       
│   ├── Scopes          
│   ├── Services        
│   └── Traits          
└── tests               # Test files
    ├── Feature         
    └── Unit            

安装

通过Composer

$ composer require neptunesoftware/laravel-invoice

您可以使用以下命令发布迁移:

$ php artisan vendor:publish --provider="NeptuneSoftware\Invoice\Providers\InvoiceServiceProvider" --tag="migrations"

迁移发布后,您可以通过运行迁移来创建发票和发票行表:

$ php artisan migrate

可选地,您还可以使用以下命令发布invoice.php配置文件:

$ php artisan vendor:publish --provider="NeptuneSoftware\Invoice\Providers\InvoiceServiceProvider" --tag="config"

默认配置文件如下所示:

return [
    'default_currency' => 'TRY',
    'default_status' => 'concept',
    'locale' => 'tr_TR',
    'table_names' => [
        'invoices' => 'invoices',
        'invoice_lines' => 'invoice_lines',
    ]
];

如果您想覆盖发票blade视图和pdf的设计,请发布视图:

$ php artisan vendor:publish --provider="NeptuneSoftware\Invoice\Providers\InvoiceServiceProvider" --tag="views"

现在您可以在<project_root>/resources/views/invoice/receipt.blade.php中编辑receipt.blade.php以匹配您的风格。

用法

货币金额以分表示!

将HasInvoice特性添加到需要发送或接收发票的Eloquent模型中(通常是Customer或Company模型)

use Illuminate\Database\Eloquent\Model;
use NeptuneSoftware\Invoice\Traits\HasInvoice;

class Order extends Model
{
    use HasInvoice; // enables the ->invoices() Eloquent relationship
}

现在您可以为客户创建发票

$customer = Customer::first();
$product = Product::first(); // Any model to be referenced in an invoice line
$service = $service->create($customer); // Injected dependency 

// To add a line to the invoice, use these example parameters:
//  Amount:
//      118 (₺1,18) incl tax
//      100 (₺1,00) excl tax
//  Description: 'Some description'
//  Tax percentage: 0.18 (18%)

# Scenerio 1:
$service->addTaxPercentage('VAT', 0.18)->addAmountInclTax($product, 118, 'Some description');
$service->addTaxPercentage('VAT', 0.18)->addAmountExclTax($product, 100, 'Some description');

# Scenerio 2:
$service->addTaxFixed('VAT', 18)->addAmountInclTax($product, 118, 'Some description');
$service->addTaxFixed('VAT', 18)->addAmountExclTax($product, 100, 'Some description');

# Scenerio 3 for taxes:
$service->addTaxPercentage('VAT', 0.18)->addAmountInclTax($product, 118, 'Some description');
$service->addTaxFixed('VAT', 18)->addAmountExclTax($product, 100, 'Some description');

// Invoice totals are now updated
$invoice = $service->getInvoice();
echo $invoice->total; // 236
echo $invoice->tax; // 36

// Set additional information (optional)
$invoice->currency; // defaults to 'TRY' (see config file)
$invoice->status; // defaults to 'concept' (see config file)
$invoice->receiver_info; // defaul ts to null
$invoice->sender_info; // defaults to null
$invoice->payment_info; // defaults to null
$invoice->note; // defaults to null

// access individual invoice lines using Eloquent relationship
$service->lines;
$service->lines();

// Access as pdf
$service->download(); // download as pdf (returns http response)
$service->pdf(); // or just grab the pdf (raw bytes)

// Handling discounts
// By adding a line with a negative amount.
$invoice = $invoice->setReference($product)->addAmountInclTax(-118, 'A nice discount', 0.18);

// Or by applying the discount and discribing the discount manually
$invoice = $invoice->setReference($product)->addAmountInclTax(118 * (1 - 0.30), 'Product XYZ incl 30% discount', 0.18);

// Convenience methods
$service->findByReference($reference);
$service->findByReferenceOrFail($reference);
$service->invoicable() // Access the related model

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

测试

$ composer test

贡献

请参阅CONTRIBUTINGCONDUCT以获取详细信息。

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件