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/ */
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',
],
],
]
);
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
}
}