visanduma/laravel-invoice

用于管理发票的简单包

v0.1.0 2022-01-07 08:05 UTC

This package is auto-updated.

Last update: 2024-09-09 07:32:27 UTC


README

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

为Laravel提供的另一个简单且强大的发票包

安装

您可以通过composer安装此包

composer require visanduma/laravel-invoice

您可以使用以下命令发布和运行迁移

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

使用方法

模型配置

使用InvoiceAble特质将任何模型转换为可开票的

use Visanduma\LaravelInvoice\Helpers\Traits\InvoiceAble;

class Customer extends Model
{
    use InvoiceAble;

	...
}

现在您的模型已准备好创建发票

创建发票

$customer->invoices()->create([
	'invoice_date' => now(),
	'tag' => 'default'  // optional. just for identification
])

// or

$invoice = Invoice::make();
$customer->attachInvoice($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 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'

为发票添加付款

$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()

为发票添加折扣/税费

// set flat discount amount
$invoice->setDiscount(50)

// set percentage of discount
$invoice->setDiscount('5%')

// add tax
$invoice->addTax('VAT', 12) // 12 equals to 12%

为发票项目添加折扣

// set flat discount amount
$invoiceItem->setDiscount(50)

// set percentage of discount
$invoiceItem->setDiscount('5%')

发票计算

$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

发票项目助手

$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()

发票助手

// 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 $

生成发票数据数组

$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."
  ]

测试

composer test

更新日志

请参阅更新日志获取最近更改的更多信息。

贡献

请参阅贡献指南获取详细信息。

安全漏洞

请查阅我们的安全策略了解如何报告安全漏洞。

致谢

许可

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