PHPackages                             tourze/bill-order-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/bill-order-bundle

ActiveSymfony-bundle

tourze/bill-order-bundle
========================

提供账单管理和订单处理功能的 Symfony 包

0.0.1(5mo ago)00MITPHPCI passing

Since Nov 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/bill-order-bundle)[ Packagist](https://packagist.org/packages/tourze/bill-order-bundle)[ RSS](/packages/tourze-bill-order-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (39)Versions (2)Used By (0)

BillOrderBundle
===============

[](#billorderbundle)

[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)[![Build Status](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)[![Code Coverage](https://camo.githubusercontent.com/744c00df8131f857793f981ddd5c53060b79c0f6d949349ca67e81b5bd5e4361/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d25334539352532352d627269676874677265656e)](https://camo.githubusercontent.com/744c00df8131f857793f981ddd5c53060b79c0f6d949349ca67e81b5bd5e4361/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d25334539352532352d627269676874677265656e)

[English](README.md) | [中文](README.zh-CN.md)

A Symfony bundle for managing bill orders with items, status tracking, and automated calculations.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Creating a Bill](#creating-a-bill)
    - [Managing Bill Status](#managing-bill-status)
    - [Console Commands](#console-commands)
- [Entities](#entities)
    - [BillOrder](#billorder)
    - [BillItem](#billitem)
- [Exceptions](#exceptions)
- [Events](#events)
- [Testing](#testing)
- [Dependencies](#dependencies)
    - [Core Dependencies](#core-dependencies)
    - [Bundle Dependencies](#bundle-dependencies)
- [Advanced Usage](#advanced-usage)
    - [Custom Bill Number Generation](#custom-bill-number-generation)
    - [Complex Queries](#complex-queries)
    - [Event Integration](#event-integration)
    - [Performance Optimization](#performance-optimization)
- [License](#license)

Features
--------

[](#features)

- Bill order management with status workflow (Draft → Pending → Paid → Completed)
- Bill items with quantity and price calculations
- Automatic total amount calculation
- Status tracking for both bills and items
- Built-in console commands for cleanup and statistics
- IP tracking for creation and updates
- User tracking (created by/updated by)
- Comprehensive exception handling

Installation
------------

[](#installation)

```
composer require tourze/bill-order-bundle
```

Configuration
-------------

[](#configuration)

Register the bundle in your `config/bundles.php`:

```
return [
    // ...
    Tourze\Symfony\BillOrderBundle\BillOrderBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

### Creating a Bill

[](#creating-a-bill)

```
use Tourze\Symfony\BillOrderBundle\Service\BillOrderService;

// Inject the service
public function __construct(private BillOrderService $billOrderService) {}

// Create a new bill
$bill = $this->billOrderService->createBill(
    title: 'Monthly Subscription',
    remark: 'January 2025 subscription'
);

// Add items to the bill
$this->billOrderService->addItemToBill(
    bill: $bill,
    productId: '12345',
    productName: 'Premium Plan',
    price: '99.99',
    quantity: 1,
    remark: 'Monthly subscription fee'
);

// Confirm the bill (change status to pending)
$this->billOrderService->confirmBill($bill);
```

### Managing Bill Status

[](#managing-bill-status)

```
// Mark bill as paid
$this->billOrderService->markAsPaid($bill);

// Complete the bill
$this->billOrderService->completeBill($bill);

// Cancel the bill
$this->billOrderService->cancelBill($bill);
```

### Console Commands

[](#console-commands)

```
# Clean up old draft bills
php bin/console bill:cleanup --days=30

# Show bill statistics
php bin/console bill:statistics --format=table
```

Entities
--------

[](#entities)

### BillOrder

[](#billorder)

The main bill entity with the following properties:

- `id`: Snowflake ID (auto-generated)
- `status`: Bill status (draft, pending, paid, completed, cancelled)
- `totalAmount`: Calculated total amount
- `title`: Optional bill title
- `billNumber`: Auto-generated bill number
- `remark`: Optional remark
- `payTime`: Payment timestamp
- `items`: Collection of bill items

### BillItem

[](#billitem)

Individual items within a bill:

- `id`: Snowflake ID (auto-generated)
- `bill`: Parent bill reference
- `status`: Item status (pending, confirmed, cancelled)
- `productId`: Product identifier
- `productName`: Product name
- `price`: Unit price
- `quantity`: Item quantity
- `subtotal`: Auto-calculated subtotal
- `remark`: Optional remark

Exceptions
----------

[](#exceptions)

- `BillOrderException`: Base exception for all bill-related errors
- `EmptyBillException`: Thrown when attempting to confirm an empty bill
- `InvalidBillStatusException`: Thrown when invalid status transitions are attempted

Events
------

[](#events)

The bundle does not currently dispatch events but is designed to be easily extended with event dispatching capabilities.

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/bill-order-bundle/tests
```

Dependencies
------------

[](#dependencies)

### Core Dependencies

[](#core-dependencies)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- Brick/Math for precise decimal calculations

### Bundle Dependencies

[](#bundle-dependencies)

- `tourze/doctrine-indexed-bundle`: Database indexing support
- `tourze/doctrine-snowflake-bundle`: Snowflake ID generation
- `tourze/doctrine-timestamp-bundle`: Automatic timestamp management
- `tourze/doctrine-user-bundle`: User tracking capabilities
- `tourze/doctrine-ip-bundle`: IP address tracking
- `tourze/enum-extra`: Enhanced enum functionality
- `tourze/symfony-cron-job-bundle`: Scheduled task support

Advanced Usage
--------------

[](#advanced-usage)

### Custom Bill Number Generation

[](#custom-bill-number-generation)

```
use Tourze\Symfony\BillOrderBundle\Entity\BillOrder;

// Override the bill number generation
$bill = new BillOrder();
$bill->setBillNumber('BILL-' . date('Y') . '-' . str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT));
```

### Complex Queries

[](#complex-queries)

```
use Tourze\Symfony\BillOrderBundle\Repository\BillOrderRepository;

// Find bills by date range and status
$bills = $repository->createQueryBuilder('b')
    ->where('b.status = :status')
    ->andWhere('b.createTime BETWEEN :start AND :end')
    ->setParameter('status', BillOrderStatus::PAID)
    ->setParameter('start', $startDate)
    ->setParameter('end', $endDate)
    ->orderBy('b.createTime', 'DESC')
    ->getQuery()
    ->getResult();
```

### Event Integration

[](#event-integration)

```
// Listen for bill status changes (example implementation)
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class BillStatusSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            'bill.status.changed' => 'onBillStatusChanged',
        ];
    }

    public function onBillStatusChanged(BillStatusChangedEvent $event): void
    {
        // Custom logic when bill status changes
        $bill = $event->getBill();
        $oldStatus = $event->getOldStatus();
        $newStatus = $event->getNewStatus();

        // Send notifications, update external systems, etc.
    }
}
```

### Performance Optimization

[](#performance-optimization)

```
// Use bulk operations for large datasets
$batchSize = 100;
for ($i = 0; $i < count($bills); $i += $batchSize) {
    $batch = array_slice($bills, $i, $batchSize);
    foreach ($batch as $bill) {
        $this->billOrderService->processBill($bill);
    }
    $entityManager->flush();
    $entityManager->clear();
}
```

License
-------

[](#license)

MIT License. See LICENSE file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance72

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

179d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-bill-order-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-bill-order-bundle/health.svg)](https://phpackages.com/packages/tourze-bill-order-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
