{
	"info": {
		"_postman_id": "cpo-item-approval-2026-02-19",
		"name": "Customer PO Item-Level Approval",
		"description": "API endpoints for approving, rejecting, and managing individual items within a Customer Purchase Order (PO).\n\nThese endpoints enable partial approval workflow where specific items can be approved while others remain pending or are rejected.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Approve Items",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Content-Type",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"item_ids\": [1, 2, 3],\n    \"notes\": \"Items verified and approved for procurement\"\n}"
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id/approve-items",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id",
						"approve-items"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Approve selected items within a Customer Purchase Order.\n\n**Request Body:**\n- `item_ids` (required): Array of Customer PO Item IDs to approve\n- `notes` (optional): Approval notes (max 2000 characters)\n\n**Business Rules:**\n- Only pending items can be approved\n- Already processed items will throw an error\n- PO status auto-updates based on item statuses:\n  - All approved → `approved`\n  - Some approved → `partially_approved`\n- Quotation status updates to `po_partially_approved` or `po_approved`"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "POST",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"item_ids\": [1, 2],\n    \"notes\": \"Items verified and approved\"\n}"
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Selected items approved successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"status\": \"partially_approved\",\n        \"aggregated_approval_status\": \"partially_approved\",\n        \"item_approval_stats\": {\n            \"total\": 5,\n            \"pending\": 3,\n            \"approved\": 2,\n            \"rejected\": 0,\n            \"suspended\": 0,\n            \"approved_total\": 5000.00,\n            \"pending_total\": 7500.00\n        },\n        \"items\": [\n            {\n                \"id\": 1,\n                \"item_name\": \"Steel Pipes\",\n                \"quantity\": 100,\n                \"unit_price\": 25.00,\n                \"total\": 2500.00,\n                \"approval_status\": \"approved\",\n                \"approved_by\": 5,\n                \"approved_at\": \"2026-02-19T10:30:00+00:00\",\n                \"approved_by_user\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                }\n            }\n        ]\n    }\n}"
				}
			]
		},
		{
			"name": "Reject Items",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Content-Type",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"item_ids\": [4, 5],\n    \"reason\": \"Price exceeds approved budget allocation\"\n}"
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id/reject-items",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id",
						"reject-items"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Reject selected items within a Customer Purchase Order.\n\n**Request Body:**\n- `item_ids` (required): Array of Customer PO Item IDs to reject\n- `reason` (required): Rejection reason (max 2000 characters)\n\n**Business Rules:**\n- Rejected items cannot be included in Supplier PO creation\n- Rejected items can be requoted if needed\n- PO status auto-updates based on item statuses"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "POST",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"item_ids\": [4],\n    \"reason\": \"Price exceeds budget\"\n}"
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Selected items rejected successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"status\": \"partially_approved\",\n        \"items\": [\n            {\n                \"id\": 4,\n                \"item_name\": \"Premium Valves\",\n                \"approval_status\": \"rejected\",\n                \"rejected_by\": 5,\n                \"rejected_at\": \"2026-02-19T10:35:00+00:00\",\n                \"approval_notes\": \"Price exceeds budget\"\n            }\n        ]\n    }\n}"
				}
			]
		},
		{
			"name": "Suspend Items",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Content-Type",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"item_ids\": [6],\n    \"reason\": \"Awaiting additional budget approval from management\"\n}"
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id/suspend-items",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id",
						"suspend-items"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Suspend selected items within a Customer Purchase Order.\n\n**Request Body:**\n- `item_ids` (required): Array of Customer PO Item IDs to suspend\n- `reason` (required): Suspension reason (max 2000 characters)\n\n**Use Case:**\n- Temporarily hold items pending further review\n- Items awaiting additional approvals\n- Items with unresolved queries"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "POST",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"item_ids\": [6],\n    \"reason\": \"Awaiting budget approval\"\n}"
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Selected items suspended successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"status\": \"partially_approved\",\n        \"items\": [\n            {\n                \"id\": 6,\n                \"item_name\": \"Special Equipment\",\n                \"approval_status\": \"suspended\",\n                \"approval_notes\": \"Awaiting budget approval\"\n            }\n        ]\n    }\n}"
				}
			]
		},
		{
			"name": "Reactivate Items",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Content-Type",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"item_ids\": [4, 6],\n    \"notes\": \"Items reactivated for re-evaluation after price negotiation\"\n}"
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id/reactivate-items",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id",
						"reactivate-items"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Reactivate (reset to pending) selected items within a Customer Purchase Order.\n\n**Request Body:**\n- `item_ids` (required): Array of Customer PO Item IDs to reactivate\n- `notes` (optional): Reactivation notes (max 2000 characters)\n\n**Use Case:**\n- Reset rejected or suspended items back to pending\n- Allow items to be re-evaluated\n- Clears previous approval/rejection data"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "POST",
						"body": {
							"mode": "raw",
							"raw": "{\n    \"item_ids\": [4],\n    \"notes\": \"Re-evaluating after price negotiation\"\n}"
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Selected items reactivated successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"status\": \"partially_approved\",\n        \"items\": [\n            {\n                \"id\": 4,\n                \"item_name\": \"Premium Valves\",\n                \"approval_status\": \"pending\",\n                \"approved_by\": null,\n                \"approved_at\": null,\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"approval_notes\": \"Re-evaluating after price negotiation\"\n            }\n        ]\n    }\n}"
				}
			]
		},
		{
			"name": "Get Item Approval Summary",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id/item-approval-summary",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id",
						"item-approval-summary"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Get detailed approval summary for all items in a Customer Purchase Order.\n\n**Response includes:**\n- Aggregated approval status\n- Statistics (total, pending, approved, rejected, suspended counts)\n- Financial totals by status\n- Detailed item-by-item approval information"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "GET"
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Item approval summary retrieved successfully.\",\n    \"data\": {\n        \"po_id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"aggregated_status\": \"partially_approved\",\n        \"stats\": {\n            \"total\": 5,\n            \"pending\": 1,\n            \"approved\": 3,\n            \"rejected\": 1,\n            \"suspended\": 0,\n            \"approved_total\": 7500.00,\n            \"pending_total\": 2500.00\n        },\n        \"items\": [\n            {\n                \"id\": 1,\n                \"item_name\": \"Steel Pipes\",\n                \"quantity\": 100,\n                \"unit_price\": 25.00,\n                \"total\": 2500.00,\n                \"approval_status\": \"approved\",\n                \"approved_by\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                },\n                \"approved_at\": \"2026-02-19T10:30:00+00:00\",\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"approval_notes\": \"Verified and approved\"\n            },\n            {\n                \"id\": 2,\n                \"item_name\": \"Copper Fittings\",\n                \"quantity\": 50,\n                \"unit_price\": 50.00,\n                \"total\": 2500.00,\n                \"approval_status\": \"approved\",\n                \"approved_by\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                },\n                \"approved_at\": \"2026-02-19T10:30:00+00:00\",\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"approval_notes\": \"Verified and approved\"\n            },\n            {\n                \"id\": 3,\n                \"item_name\": \"PVC Joints\",\n                \"quantity\": 200,\n                \"unit_price\": 12.50,\n                \"total\": 2500.00,\n                \"approval_status\": \"approved\",\n                \"approved_by\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                },\n                \"approved_at\": \"2026-02-19T10:31:00+00:00\",\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"approval_notes\": null\n            },\n            {\n                \"id\": 4,\n                \"item_name\": \"Premium Valves\",\n                \"quantity\": 10,\n                \"unit_price\": 500.00,\n                \"total\": 5000.00,\n                \"approval_status\": \"rejected\",\n                \"approved_by\": null,\n                \"approved_at\": null,\n                \"rejected_by\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                },\n                \"rejected_at\": \"2026-02-19T10:35:00+00:00\",\n                \"approval_notes\": \"Price exceeds budget\"\n            },\n            {\n                \"id\": 5,\n                \"item_name\": \"Special Gaskets\",\n                \"quantity\": 100,\n                \"unit_price\": 25.00,\n                \"total\": 2500.00,\n                \"approval_status\": \"pending\",\n                \"approved_by\": null,\n                \"approved_at\": null,\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"approval_notes\": null\n            }\n        ]\n    }\n}"
				}
			]
		},
		{
			"name": "Get Customer PO Details",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Accept",
						"value": "application/json"
					},
					{
						"key": "Authorization",
						"value": "Bearer {{ACCESS_TOKEN}}"
					}
				],
				"url": {
					"raw": "{{BASE_URL}}/supply/customer-purchase-orders/:po_id",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"customer-purchase-orders",
						":po_id"
					],
					"variable": [
						{
							"key": "po_id",
							"value": "1",
							"description": "Customer Purchase Order ID"
						}
					]
				},
				"description": "Get full details of a Customer Purchase Order including item-level approval information.\n\n**Response now includes:**\n- `aggregated_approval_status`: Computed status based on item approvals\n- `item_approval_stats`: Statistics object with counts and totals\n- Each item includes approval fields (status, approved_by, etc.)"
			},
			"response": [
				{
					"name": "Success Response",
					"originalRequest": {
						"method": "GET"
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"body": "{\n    \"success\": true,\n    \"message\": \"Customer Purchase Order retrieved successfully.\",\n    \"data\": {\n        \"id\": 1,\n        \"po_number\": \"CPO-2026-0001\",\n        \"po_date\": \"2026-02-19\",\n        \"payment_method\": \"Credit (30 days)\",\n        \"required_delivery_time\": \"2 weeks\",\n        \"status\": \"partially_approved\",\n        \"aggregated_approval_status\": \"partially_approved\",\n        \"item_approval_stats\": {\n            \"total\": 5,\n            \"pending\": 1,\n            \"approved\": 3,\n            \"rejected\": 1,\n            \"suspended\": 0,\n            \"approved_total\": 7500.00,\n            \"pending_total\": 2500.00\n        },\n        \"match_status\": \"matched\",\n        \"match_notes\": null,\n        \"supply_quotation\": {\n            \"id\": 10,\n            \"quotation_number\": \"SQ-2026-0010\",\n            \"status\": \"po_partially_approved\"\n        },\n        \"items\": [\n            {\n                \"id\": 1,\n                \"item_name\": \"Steel Pipes\",\n                \"quantity\": 100,\n                \"unit_price\": 25.00,\n                \"total\": 2500.00,\n                \"order\": 1,\n                \"quotation_item_id\": 15,\n                \"approval_status\": \"approved\",\n                \"approved_by\": 5,\n                \"approved_at\": \"2026-02-19T10:30:00+00:00\",\n                \"approved_by_user\": {\n                    \"id\": 5,\n                    \"name\": \"John Doe\"\n                },\n                \"rejected_by\": null,\n                \"rejected_at\": null,\n                \"rejected_by_user\": null,\n                \"approval_notes\": \"Verified and approved\"\n            }\n        ],\n        \"created_at\": \"2026-02-18 14:00:00\",\n        \"updated_at\": \"2026-02-19 10:35:00\"\n    }\n}"
				}
			]
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "BASE_URL",
			"value": "http://localhost/api/v1",
			"type": "string"
		},
		{
			"key": "ACCESS_TOKEN",
			"value": "your-access-token-here",
			"type": "string"
		}
	]
}
