visanduma/laravel-invoice
Composer 安装命令:
composer require visanduma/laravel-invoice
包简介
Simple package to manage invoices
README 文档
README
Yet another simple & powerful invoicing package for Laravel
Installation
You can install the package via composer:
composer require visanduma/laravel-invoice
You can publish and run the migrations with:
php artisan vendor:publish --tag="invoice-migrations"
php artisan migrate
Usage
Model configuration
Make any model invoice-able using InvoiceAble trait
use Visanduma\LaravelInvoice\Helpers\Traits\InvoiceAble; class Customer extends Model { use InvoiceAble; ... }
now your model is ready to create invoices
Create invoice
$customer->invoices()->create([ 'invoice_date' => now(), 'tag' => 'default' // optional. just for identification ]) // or $invoice = Invoice::make(); $customer->attachInvoice($invoice)
Add items to invoice
// adding single item $invoice->items()->create([ 'name' => 'Product one', 'price' => 150, 'qty' => 1, // optional fields 'description' => 'tiny description', 'unit' => 'Nos', 'tag' => '', 'discount' => 0, 'discount_type' => InvoiceItem::DISCOUNT_FLAT, ]); // adding multiple items $invoice->items()->createMany([ ['name' => 'Product 2', 'price' => 100, 'qty' => 2], ['name' => 'Product 3', 'price' => 80, 'qty' => 1], ]);
Adding additional information to invoice
// adding single value $invoice->setExtraValue('something','and its value') // adding multiple values at once $invoice->setExtraValues([ 'something' => '', 'another thing' => 'another value' ]) // retrieve back extra values $invoice->getExtraValue('something') // returns 'and its value'
Add payment for invoice
$invoice->addPayment(100) $invoice->addPayment(100,'advance payment') // pay with note $invoice->addPayment(-10) // use minus values to make deduction // get total of paid $invoice->paidAmount() // 190 (100 + 100 - 10) // get payment due amount $invoice->dueAmount()
Add discount/tax to invoice
// set flat discount amount $invoice->setDiscount(50) // set percentage of discount $invoice->setDiscount('5%') // add tax $invoice->addTax('VAT', 12) // 12 equals to 12%
Add discount to invoice item
// set flat discount amount $invoiceItem->setDiscount(50) // set percentage of discount $invoiceItem->setDiscount('5%')
Calculation of invoice
$invoice->items()->createMany([ ['name' => 'Product 2', 'price' => 100, 'qty' => 2], ['name' => 'Product 3', 'price' => 80, 'qty' => 1], ]); // get total amount of invoice items $invoice->getItemsTotal() // 280
Invoice item helpers
$item = InvoiceItem::create([ 'name' => 'Product one', 'price' => 100, 'qty' => 1, ]) // Set discount per item $item->setDiscount(10) // total is 90 $item->setDiscount('50%') // total is 50 // get total amount $item->total //get total without discount $item->totalWithoutDiscount()
Invoice helpers
// find invoice by invoice number $customer->findInvoiceByNumber('INV000001') // update invoice status $invoice->setStatus(Invoice::STATUS_COMPLETED) $invoice->setStatus(Invoice::STATUS_DRAFT) $invoice->setStatus(Invoice::STATUS_SENT) // get status $invoice->status // update payment status $invoice->setPaymentStatus(Invoice::STATUS_UNPAID) $invoice->setPaymentStatus(Invoice::STATUS_PAID) // get paid status $invoice->paid_status // get invoice total without taxes & invoice discount $invoice->getItemsTotal() // invoice item count $invoice->getItemCount() // invoice due $invoice->dueAmount() // invoiced tax $invoice->totalTaxAmount() // invoice total $invoice->total // set invoice currency symbol $invoice->setCurrency('Rs.') // default is $
Generate invoice data array
$invoice->toArray() // output [ "from" => [ "name" => "Seller name" "address" => "Seller Street one, City, PO CODE" "contact" => "" "extra" => "" ] "to" => [ "name" => "Customer name" "address" => "Street one, City, PO CODE" "contact" => "" "extra" => "" ] "items" => [ 0 => [ "id" => 1 "invoice_id" => "1" "name" => "product 1" "description" => null "discount" => 0.0 "discount_value" => 0.0 "discount_type" => null "price" => 100.0 "qty" => 2 "unit" => null "total" => 200.0 "item_id" => null "tag" => null "created_at" => "2022-09-02 07:43:10" "updated_at" => "2022-09-02 07:43:10" ] 1 => [ "id" => 2 "invoice_id" => "1" "name" => "product 2" "description" => null "discount" => 0.0 "discount_value" => 0.0 "discount_type" => null "price" => 150.0 "qty" => 1 "unit" => null "total" => 150.0 "item_id" => null "tag" => null "created_at" => "2022-09-02 07:43:10" "updated_at" => "2022-09-02 07:43:10" ] ] "payments" => [ 0 => [ "id" => 1 "invoice_id" => "1" "method" => "CASH" "amount" => "50" "note" => "I paid" "payment_date" => "2022-09-02 07:43:10" "created_at" => "2022-09-02 07:43:10" "updated_at" => "2022-09-02 07:43:10" ] ] "taxes" => [ 0 => [ "name" => "VAT" "value" => 12 "amount" => 42 ] 1 => [ "name" => "NBT" "value" => 5 "amount" => 17.5 ] ] "summary" => [ "items_count" => 2 "gross_total" => "Rs.350.00" "total" => "Rs.409.50" "discount" => "Rs.0.00" "paid_amount" => "Rs.50.00" "due_amount" => "Rs.359.50" "tax_total" => "Rs.59.50" "status" => "DRAFT" "date" => "2022-09-02 07:43:10" "currency" => "Rs." ]
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.
visanduma/laravel-invoice 适用场景与选型建议
visanduma/laravel-invoice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Laravel-Invoice」 「Visanduma」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 visanduma/laravel-invoice 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 visanduma/laravel-invoice 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 visanduma/laravel-invoice 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The missing Back button of NOVA
Simple user switch for development environment
Simple user switch for development environment
This is my package laravel-hrm
Alfabank REST API integration
This is my package laravel-invoice
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-07