tourze / bill-order-bundle
提供账单管理和订单处理功能的 Symfony 包
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/bill-order-bundle
Requires
- ext-date: *
- ext-json: *
- ext-spl: *
- brick/math: ^0.13
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- monolog/monolog: ^3.1
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/uid: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-ip-bundle: 1.1.*
- tourze/doctrine-snowflake-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-enum-field-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/symfony-cron-job-bundle: 1.1.*
- tourze/symfony-dependency-service-loader: 1.0.*
Requires (Dev)
- doctrine/data-fixtures: ^2.0
- doctrine/doctrine-fixtures-bundle: ^4.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-base: 1.*
- tourze/phpunit-doctrine-entity: 1.*
- tourze/phpunit-enum: 1.*
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
- tourze/phpunit-symfony-web-test: 1.*
This package is auto-updated.
Last update: 2025-11-14 08:29:28 UTC
README
A Symfony bundle for managing bill orders with items, status tracking, and automated calculations.
Table of Contents
- Features
- Installation
- Configuration
- Usage
- Entities
- Exceptions
- Events
- Testing
- Dependencies
- Advanced Usage
- License
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
composer require tourze/bill-order-bundle
Configuration
Register the bundle in your config/bundles.php:
return [ // ... Tourze\Symfony\BillOrderBundle\BillOrderBundle::class => ['all' => true], ];
Usage
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
// Mark bill as paid $this->billOrderService->markAsPaid($bill); // Complete the bill $this->billOrderService->completeBill($bill); // Cancel the bill $this->billOrderService->cancelBill($bill);
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
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 amounttitle: Optional bill titlebillNumber: Auto-generated bill numberremark: Optional remarkpayTime: Payment timestampitems: Collection of bill items
BillItem
Individual items within a bill:
id: Snowflake ID (auto-generated)bill: Parent bill referencestatus: Item status (pending, confirmed, cancelled)productId: Product identifierproductName: Product nameprice: Unit pricequantity: Item quantitysubtotal: Auto-calculated subtotalremark: Optional remark
Exceptions
BillOrderException: Base exception for all bill-related errorsEmptyBillException: Thrown when attempting to confirm an empty billInvalidBillStatusException: Thrown when invalid status transitions are attempted
Events
The bundle does not currently dispatch events but is designed to be easily extended with event dispatching capabilities.
Testing
Run the test suite:
./vendor/bin/phpunit packages/bill-order-bundle/tests
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
tourze/doctrine-indexed-bundle: Database indexing supporttourze/doctrine-snowflake-bundle: Snowflake ID generationtourze/doctrine-timestamp-bundle: Automatic timestamp managementtourze/doctrine-user-bundle: User tracking capabilitiestourze/doctrine-ip-bundle: IP address trackingtourze/enum-extra: Enhanced enum functionalitytourze/symfony-cron-job-bundle: Scheduled task support
Advanced Usage
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
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
// 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
// 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
MIT License. See LICENSE file for details.