psys / order-invoice-manager-bundle
Symfony bundle to keep your orders and invoices under control
Installs: 37
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- doctrine/doctrine-bundle: ^2.14
- doctrine/orm: ^3.3
- psys/utils: ^1.0.10
- twig/twig: ^3.21
README
Use case
- You need to manage orders and associated invoices.
- You're not running a typical online store — full-featured e-commerce platforms would be overkill.
Installation
composer req psys/order-invoice-manager-bundle
1. Set your customer entity
# config/packages/doctrine.yaml orm: resolve_target_entities: Psys\OrderInvoiceManagerBundle\Model\CustomerInterface: App\Entity\YourCustomerEntity
2. Init database
symfony console make:migration
Then rename the migrations/VersionOimbInit.php
(also the class inside), so it runs just after the migration you've just created.
symfony console doctrine:migrations:migrate
Optional steps after installation
Define categories for orders and/or its items
namespace App\Lib; enum MyOrderItemCategory :int { case FOO = 1; case BAR = 2; }
Example usage
Creating a new order a and its proforma invoice:
use Psys\OrderInvoiceManagerBundle\Entity\Invoice; use Psys\OrderInvoiceManagerBundle\Entity\InvoiceBuyer; use Psys\OrderInvoiceManagerBundle\Entity\InvoiceProforma; use Psys\OrderInvoiceManagerBundle\Entity\InvoiceSeller; use Psys\OrderInvoiceManagerBundle\Entity\Order; use Psys\OrderInvoiceManagerBundle\Entity\OrderItem; use Psys\OrderInvoiceManagerBundle\Model\OrderItem\AmountType; use Psys\OrderInvoiceManagerBundle\Model\Order\PaymentMode; use Psys\OrderInvoiceManagerBundle\Model\Order\State; use Psys\OrderInvoiceManagerBundle\Service\InvoiceManager; use Symfony\Bundle\SecurityBundle\Security; public function create_order (OrderManager $orderManager, InvoiceManager $invoiceManager, Security $security) { $ent_Order = new Order(); $ent_Order->setCategory(MyOrderCategory::FOO); $ent_Order->setPaymentMode(PaymentMode::BANK_ACCOUNT_REGULAR); $ent_Order->setPaymentModeBankAccount('5465878565/6556'); $ent_Order->setCustomer($security->getUser()); // Customer can be null $ent_Order->setCreatedAt(new \DateTimeImmutable()); $ent_Order->setState(State::NEW); $ent_Order->addOrderItem( (new OrderItem()) ->setName('Foo') ->setPriceVatIncluded(1599) // If not set, it will be automatically calculated from price exclusive of VAT ->setPriceVatExcluded(1300) // If not set, it will be automatically calculated from price inclusive of VAT ->setVatRate(21) ->setAmount(1) ->setAmountType(AmountType::ITEM) ); $ent_InvoiceProforma = (new InvoiceProforma()) ->setCreatedAt(new \DateTimeImmutable()) ->setDueDate(new \DateTimeImmutable('+14 days')); $invoiceManager->setSequentialNumber($ent_InvoiceProforma); $ent_InvoiceProforma->setReferenceNumber(date('Y').$ent_InvoiceProforma->getSequentialNumber()); // Use custom formatting for the reference number $ent_Invoice = (new Invoice()) ->setInvoiceProforma($ent_InvoiceProforma) ->setInvoiceBuyer ( (new InvoiceBuyer()) ->setName('Some Buyer') ->setStreetAddress1('Street 123') ->setCity('Some City') ->setPostcode('25689') ->setVatIdentificationNumber('5468484') ->setCompanyIdentificationNumber('5655') ) ->setInvoiceSeller ( (new InvoiceSeller()) ->setName('Some Seller') ->setStreetAddress1('Street 123') ->setCity('Some City') ->setPostcode('25689') ->setVatIdentificationNumber('5468484') ->setCompanyIdentificationNumber('5655') ); $invoiceManager->setUniqueVariableSymbol($ent_Invoice); $ent_Order->setInvoice($ent_Invoice); $orderManager->processAndSaveNewOrder($ent_Order); }
Reseting sequential numbers:
use App\Lib\InvoiceManager; public function reset_sequential_numbers (InvoiceManager $invoiceManager) { // This method is meant to be used inside a cron. // This cron needs to be run 1 to 10 minutes before a new year. $invoiceManager->resetSequentialNumbersEveryYear(); // Use this method for resetting sequential numbers whenever you want. $invoiceManager->resetSequentialNumbers(); }