How mhdniyas/green-leaf-erp works
Purpose and entry points
A Laravel ERP/operations system for procurement, inventory, warehouses, shop ordering/delivery, sales, finance/cashbook, and HR/payroll. HTTP entry points are server-rendered web routes and a versioned API: routes/web.php, routes/api.php. Laravel boots through public/index.php and bootstrap/app.php; scheduled/operational work enters through artisan and routes/console.php.
Delivery surfaces and access boundary
Web controllers provide role-specific workspaces for administrators, purchasers, shop owners, warehouse staff, inventory staff, and finance users; Blade views and Vite-built JavaScript support these workflows. APIs expose inventory, purchasing, purchaser, and warehouse operations with request validation and resource serialization.
• app/Http/Controllers/Web/Admin/FinanceV2Controller.php
• app/Http/Controllers/Api/Inventory/StockBatchController.php
• app/Http/Middleware/ApiVersionMiddleware.php
Authorization is policy-based, with authentication/Sanctum configuration and role/permission schema. Secure headers and last-seen updates are cross-cutting middleware.
• app/Policies/PurchaseOrderPolicy.php
• app/Http/Middleware/SecureHeaders.php
• config/sanctum.php
Procurement and price lifecycle
Suppliers, purchase orders, goods receipts (GRNs), purchase invoices, purchaser carts, vendor advances, and daily/grade prices form the inbound purchasing lifecycle. Controllers validate requests, then services/actions apply transitions such as recording/approving GRNs and cancelling invoices. Persistent records are Eloquent models, while DTOs and repositories provide application/data boundaries.
• app/Actions/Purchasing/RecordGoodsReceiptAction.php
• app/Actions/Purchasing/ApproveGoodsReceiptAction.php
• app/Services/Purchasing/PurchaseOrderService.php
Daily purchaser pricing is synchronized by a console command; read caching and observers support high-traffic purchaser views.
• app/Console/Commands/SyncDailyPurchaserPricesCommand.php
• app/Services/Purchasing/PurchaserReadCacheService.php
• app/Observers/PurchaserCacheInvalidationObserver.php
Inventory, receiving, sorting, and warehouse fulfillment
Inventory centers on product/category master data, stock batches, movements, adjustments, wastage, daily closes, and sorting. Stock is ledger-oriented: operational mutations flow through inventory services/actions and generate stock movements. Batch sorting has explicit quantity and already-sorted failure boundaries.
• app/Services/Inventory/StockLedgerService.php
• app/Actions/Inventory/ProcessBatchSortingAction.php
• app/Models/StockMovement.php
Warehouse flows receive purchased/direct stock, scope loadout work by warehouse, and fulfill shop orders. Loadout state and completion are persisted separately, supporting idempotent client-side saves and delivery handoff.
• app/Services/Warehouse/WarehouseScopedLoadoutService.php
• app/Services/Warehouse/WarehouseLoadoutCompletionService.php
• app/Models/ShopOrderLoadoutState.php
Shop requisitions, delivery, and invoicing
Shops submit and revise orders; requisition services synchronize item quantities and record change history. Warehouse loadouts produce deliveries, which shop owners can receive/review; discrepancies and delivery-review resolution are explicit workflow stages. Shop invoices and payment requests convert fulfilled demand into receivable/payment processes.
• app/Services/Requisition/ShopOrderRevisionService.php
• app/Domains/ShopOrder/Actions/ResolveDeliveryReviewAction.php
• app/Services/ShopInvoices/ShopInvoiceService.php
Finance, cashbook, and HR
Finance is a separate but integrated accounting layer: journals, company accounts/payables, shop accounting, vendor settlements, direct company sales, and cashbook ledgers/reconciliation. Operational events such as expenses, sales, invoice activity, and payroll are posted/projection-managed by dedicated services rather than controllers.
• app/Services/Finance/JournalService.php
• app/Services/Cashbook/TransactionGenerator.php
• app/Services/Cashbook/CompanyPaymentReconciliationService.php
HR maintains employee directories, attendance, leave ledgers, advances, assignments, payroll runs, and payments; payroll can feed finance/cashbook flows.
• app/Services/HR/PayrollService.php
• app/Services/HR/LeaveLedgerService.php
• app/Models/PayrollRun.php
Runtime and infrastructure
The application runs on PHP/Laravel with Eloquent migrations and a relational database, Laravel cache/session/queue facilities, filesystem-backed storage, mail, notifications, and Vite frontend assets. Background work includes inventory-empty processing, scheduled catalog/price/reconciliation tasks, and database-backup email delivery.
• app/Jobs/ProcessInventoryEmptyBatch.php
• app/Services/Backup/DatabaseBackupService.php
• app/Mail/DatabaseBackupMail.php
Main entry points: StockLedgerService.php Stock ledger · PurchaseOrderService.php Procurement lifecycle · WarehouseScopedLoadoutService.php Warehouse loadouts · web.php Web workspaces
Components 22
Entry & Access
- Web workspaces · Role-specific server-rendered operational workflows.
routes/web.php - Versioned operations API
routes/api.php - API version boundary
app/Http/Middleware/ApiVersionMiddleware.php - Policy authorization
app/Policies/PurchaseOrderPolicy.php
Operational Workflows
- Procurement lifecycle · Orders, receipts, invoices, supplier advances, carts, and prices.
app/Services/Purchasing/PurchaseOrderService.php - GRN approval · Applies goods-receipt approval transitions.
app/Actions/Purchasing/ApproveGoodsReceiptAction.php - Daily price sync
app/Console/Commands/SyncDailyPurchaserPricesCommand.php - Purchaser read cache · Invalidated by purchasing observers.
app/Services/Purchasing/PurchaserReadCacheService.php - Stock ledger · Records stock mutations as movements.
app/Services/Inventory/StockLedgerService.php - Batch sorting · Enforces available and already-sorted quantity boundaries.
app/Actions/Inventory/ProcessBatchSortingAction.php - Stock movements
app/Models/StockMovement.php - Warehouse loadouts · Scopes fulfillment work by warehouse and completes loadouts.
app/Services/Warehouse/WarehouseScopedLoadoutService.php - Loadout state · Separate persisted state supports idempotent saves.
app/Models/ShopOrderLoadoutState.php - Shop requisitions · Synchronizes revised order quantities and history.
app/Services/Requisition/ShopOrderRevisionService.php - Delivery review resolution · Resolves delivery discrepancies after handoff.
app/Domains/ShopOrder/Actions/ResolveDeliveryReviewAction.php - Shop invoicing · Converts fulfilled shop demand into receivables and payment requests.
app/Services/ShopInvoices/ShopInvoiceService.php
Finance & HR
- Finance journals · Posts and projects operational accounting events.
app/Services/Finance/JournalService.php - Cashbook & reconciliation · Generates cashbook transactions and reconciles company payments.
app/Services/Cashbook/TransactionGenerator.php - HR payroll · Manages payroll runs and payments.
app/Services/HR/PayrollService.php
Runtime Services
- Operational database · Eloquent records, migrations, and workflow state.
- Queue & scheduled work · Processes deferred inventory and operational tasks.
app/Jobs/ProcessInventoryEmptyBatch.php - Database backup delivery · Creates backups for email delivery.
app/Services/Backup/DatabaseBackupService.php
Connections 27
- Web workspaces → Policy authorization: authorizes
- Web workspaces → Procurement lifecycle: drives
- Web workspaces → Stock ledger: drives
- Web workspaces → Warehouse loadouts: drives
- Versioned operations API → API version boundary: passes through
- API version boundary → Stock ledger: inventory operations
- API version boundary → Procurement lifecycle: purchasing operations
- Procurement lifecycle → GRN approval: approves GRNs
- GRN approval → Stock ledger: receives stock
- Daily price sync → Procurement lifecycle: synchronizes prices
- Procurement lifecycle → Purchaser read cache: serves purchaser reads
- Stock ledger → Batch sorting: processes batches
- Stock ledger → Stock movements: writes ledger
- Shop requisitions → Warehouse loadouts: creates fulfillment demand
- Warehouse loadouts → Loadout state: persists progress
- Warehouse loadouts → Delivery review resolution: hands off deliveries
- Delivery review resolution → Shop invoicing: confirmed fulfillment
- Shop invoicing → Finance journals: posts receivables
- HR payroll → Finance journals: posts payroll
- Finance journals → Cashbook & reconciliation: generates transactions
- Procurement lifecycle → Operational database: persists records
- Stock ledger → Operational database: persists stock state
- Warehouse loadouts → Operational database: persists fulfillment
- Finance journals → Operational database: persists journals
- Queue & scheduled work → Stock ledger: deferred processing
- Queue & scheduled work → Daily price sync: scheduled execution
- Database backup delivery → Operational database: backs up