2lenet/invoice-bundle

发票包

安装: 17

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

3.1.0 2023-08-28 08:33 UTC

This package is not auto-updated.

Last update: 2024-09-24 12:28:53 UTC


README

这个包可以帮助你在项目中管理发票。

安装

要安装此包

composer require 2le/invoice-bundle

配置

要配置此包,在 doctrine 服务配置文件 ("config/packages/doctrine.yaml") 中,你需要定义哪个实体将获得客户的角色。

例如,如果你想使用你的 User 实体,你将在文件末尾添加此块

config/packages/doctrine.yaml:
    ...
    orm:
        ...
        resolve_target_entities:
            Lle\InvoiceBundle\Model\CustomerInterface: App\Entity\User
            Lle\InvoiceBundle\Model\ProductInterface: App\Entity\Product
            Lle\InvoiceBundle\Model\CustomerInterface: App\Entity\Guest
            Lle\InvoiceBundle\Model\ProductInterface: App\Entity\InvoiceProduct
            Lle\InvoiceBundle\Model\SellerInterface: App\Entity\Establishment
            Lle\InvoiceBundle\Model\InvoiceInterface: App\Entity\Invoice
            Lle\InvoiceBundle\Model\InvoiceLineInterface: App\Entity\InvoiceLine
            Lle\InvoiceBundle\Model\PaymentInterface: App\Entity\Payment
            Lle\InvoiceBundle\Model\PaymentConditionInterface: App\Entity\PaymentCondition
            Lle\InvoiceBundle\Model\PaymentTypeInterface: App\Entity\PaymentType
            Lle\InvoiceBundle\Model\VatRateInterface: App\Entity\VatRate

然后,当包期望一个 CustomerInterface 时,你可以传递一个用户。一旦配置了这个监听器,Doctrine 就会知道如何替换客户接口。对于 Product 实体也是如此。

要获取有关与抽象类和接口的关系的更多信息,你可以查看官方 Symfony 文档 这里

不要忘记使用包特性实现你的实体上的方法,并添加你的自定义需求。

class Invoice implements InvoiceInterface
{
    use InvoiceTrait;
    
    ...
}

PDF 参数

使用 PdfGenerator 要导出 PDF 格式的发票,你需要在 "config/packages/lle_invoice.yaml" 文件中定义参数。例如,你可以定义如下参数:

lle_invoice:
  # Relative path to image (png or jpg) from root directory
  logo: 'public/image/image.jpg'
  header: 'header \n address'
  footer: 'footer \n info'

logo: 放在发票标题中的图片路径

其他字段涉及制作示例的公司。

使用方法

在这个包中,有几个服务:InvoiceManager、InvoiceLineManager、InvoiceExporter、InvoicePDF。你可以使用它们的所有功能,并通过依赖注入使用它们。你可以使用 EasyAdmin 或 EasyAdminPlus 来管理这个实体。

发票管理器

InvoiceManager 是一个服务,允许你生成草稿发票或验证发票。

生成草稿发票

草稿发票是一个预填字段发票。

示例

    public function index(InvoiceManager $invoiceManager): Response
    {
        ...
        // To get a draft Invoice
        $invoiceManager->generate();    
        ...  
    }

但是,如果你想获取更多预填字段,你可以传递一个 实现 CustomerInterface 的实体

    public function index(InvoiceManager $invoiceManager): Response
    {
        ...
        // Entity User implements CustomerInterface in this example
        $invoiceManager->generate($user);    
        ...  
    }

验证发票

如果你想验证发票,你可以使用 InvoiceManager。验证发票会将发票号码设置为当前日期,并将状态设置为 "验证"。

示例

    public function index(InvoiceManager $invoiceManager): Response
    {
        ...
        $invoiceManager->validate($invoice);    
        ...  
    }

然后,你可以持久化你的实体或做任何你想做的事情。

发票导出器

你可以导出一个或多个发票为 csv 格式。

示例

    public function index(InvoiceExporter $invoiceExporter, Invoice $invoice): Response
    {
        ...
        $invoiceExporter->export([$invoice]);    
        ...  
    }

你可以使用:export([$invoice1, $invoice2], 'invoice_export.csv'); 来选择文件名