PHP code example of azaharizaman / nexus-procurement

1. Go to this page and download the library: Download azaharizaman/nexus-procurement library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

azaharizaman / nexus-procurement example snippets


use Nexus\Procurement\Contracts\ProcurementManagerInterface;

$procurement = app(ProcurementManagerInterface::class);

$requisition = $procurement->createRequisition(
    tenantId: 'tenant-001',
    requesterId: 'user-123',
    data: [
        'number' => 'REQ-2025-001',
        'description' => 'Office supplies for Q1',
        'department' => 'Administration',
        'lines' => [
            [
                'item_code' => 'PAPER-A4',
                'description' => 'A4 Paper 500 sheets',
                'quantity' => 10,
                'unit' => 'box',
                'estimated_unit_price' => 25.00,
            ],
        ],
    ]
);

use Nexus\Procurement\Exceptions\UnauthorizedApprovalException;

try {
    $approvedRequisition = $procurement->approveRequisition(
        requisitionId: $requisition->getId(),
        approverId: 'manager-456' // Must NOT be the requester
    );
} catch (UnauthorizedApprovalException $e) {
    // BUS-PRO-0095 violation: Requester tried to approve own requisition
}

use Nexus\Procurement\Exceptions\BudgetExceededException;

try {
    $po = $procurement->convertRequisitionToPO(
        tenantId: 'tenant-001',
        requisitionId: $requisition->getId(),
        creatorId: 'buyer-789',
        poData: [
            'number' => 'PO-2025-001',
            'vendor_id' => 'vendor-xyz',
            'lines' => [
                [
                    'requisition_line_id' => $requisition->getLines()[0]->getId(),
                    'quantity' => 10,
                    'unit_price' => 24.50, // Within 10% of estimate
                    'unit' => 'box',
                    'item_code' => 'PAPER-A4',
                    'description' => 'A4 Paper 500 sheets',
                ],
            ],
        ]
    );
} catch (BudgetExceededException $e) {
    // PO exceeds requisition by more than 10%
}

$grn = $procurement->recordGoodsReceipt(
    tenantId: 'tenant-001',
    poId: $po->getId(),
    receiverId: 'warehouse-clerk-001', // Must NOT be PO creator
    receiptData: [
        'number' => 'GRN-2025-001',
        'received_date' => '2025-11-20',
        'lines' => [
            [
                'po_line_reference' => 'PO-2025-001-L001',
                'quantity_received' => 10, // Cannot exceed PO quantity
                'unit' => 'box',
            ],
        ],
    ]
);

$matchResult = $procurement->performThreeWayMatch(
    poLine: $poLine,
    grnLine: $grnLine,
    invoiceLineData: [
        'quantity' => 10,
        'unit_price' => 24.50,
        'line_total' => 245.00,
    ]
);

if ($matchResult['matched']) {
    echo "✅ Auto-approved: {$matchResult['recommendation']}";
} else {
    echo "⚠️  Manual review: {$matchResult['recommendation']}";
    print_r($matchResult['discrepancies']);
}

use Nexus\Procurement\Exceptions\{
    RequisitionNotFoundException,
    PurchaseOrderNotFoundException,
    GoodsReceiptNotFoundException,
    InvalidRequisitionDataException,
    InvalidRequisitionStateException,
    InvalidPurchaseOrderDataException,
    InvalidGoodsReceiptDataException,
    BudgetExceededException,
    UnauthorizedApprovalException
};

try {
    $requisition = $procurement->getRequisition($requisitionId);
} catch (RequisitionNotFoundException $e) {
    // Handle requisition not found
}

try {
    $approved = $procurement->approveRequisition($id, $approverId);
} catch (UnauthorizedApprovalException $e) {
    // Handle unauthorized approval attempt
}

use Nexus\Procurement\Services\ProcurementManager;
use Nexus\Procurement\Contracts\RequisitionRepositoryInterface;
use PHPUnit\Framework\TestCase;

class ProcurementManagerTest extends TestCase
{
    public function test_create_requisition(): void
    {
        $mockRepo = $this->createMock(RequisitionRepositoryInterface::class);
        $mockRepo->expects($this->once())
            ->method('create')
            ->willReturn($this->createMock(RequisitionInterface::class));
        
        $manager = new ProcurementManager($mockRepo, ...);
        // ... test logic
    }
}

packages/Procurement/
├── src/
│   ├── Contracts/              # 19 Interfaces
│   │   ├── ProcurementManagerInterface.php
│   │   ├── RequisitionInterface.php
│   │   ├── RequisitionLineInterface.php
│   │   ├── RequisitionRepositoryInterface.php
│   │   ├── PurchaseOrderInterface.php
│   │   ├── PurchaseOrderLineInterface.php
│   │   ├── PurchaseOrderRepositoryInterface.php
│   │   ├── GoodsReceiptNoteInterface.php
│   │   ├── GoodsReceiptLineInterface.php
│   │   ├── GoodsReceiptRepositoryInterface.php
│   │   ├── VendorQuoteInterface.php
│   │   ├── VendorQuoteRepositoryInterface.php
│   │   └── ... (7 analytics repository interfaces)
│   ├── Services/               # 6 Business Logic Services
│   │   ├── ProcurementManager.php
│   │   ├── RequisitionManager.php
│   │   ├── PurchaseOrderManager.php
│   │   ├── GoodsReceiptManager.php
│   │   ├── MatchingEngine.php
│   │   └── VendorQuoteManager.php
│   └── Exceptions/             # 10 Domain Exceptions
│       ├── ProcurementException.php
│       ├── RequisitionNotFoundException.php
│       ├── PurchaseOrderNotFoundException.php
│       ├── GoodsReceiptNotFoundException.php
│       ├── InvalidRequisitionDataException.php
│       ├── InvalidRequisitionStateException.php
│       ├── InvalidPurchaseOrderDataException.php
│       ├── InvalidGoodsReceiptDataException.php
│       ├── BudgetExceededException.php
│       └── UnauthorizedApprovalException.php
├── composer.json
├── LICENSE
└── README.md