{
	"info": {
		"_postman_id": "supplier-po-from-quotation-collection",
		"name": "Supplier Purchase Orders from Quotations",
		"description": "API collection for creating Supplier Purchase Orders from approved Supply Quotations",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"variable": [
		{
			"key": "BASE_URL",
			"value": "http://localhost:8000/api/v1",
			"type": "string"
		},
		{
			"key": "access_token",
			"value": "",
			"type": "string"
		},
		{
			"key": "quotation_id",
			"value": "1",
			"type": "string"
		},
		{
			"key": "supplier_po_id",
			"value": "1",
			"type": "string"
		}
	],
	"item": [
		{
			"name": "1. List Quotations Ready for Supplier PO Creation",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{BASE_URL}}/supply/quotations-ready-for-supplier-po?per_page=15&page=1&customer_id=&date_from=&date_to=",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"quotations-ready-for-supplier-po"
					],
					"query": [
						{
							"key": "per_page",
							"value": "15",
							"description": "Items per page"
						},
						{
							"key": "page",
							"value": "1",
							"description": "Page number"
						},
						{
							"key": "customer_id",
							"value": "",
							"description": "Filter by customer ID (optional)",
							"disabled": true
						},
						{
							"key": "date_from",
							"value": "",
							"description": "Filter from date (optional)",
							"disabled": true
						},
						{
							"key": "date_to",
							"value": "",
							"description": "Filter to date (optional)",
							"disabled": true
						}
					]
				},
				"description": "Get a paginated list of quotations that are ready for supplier PO creation. These are quotations where:\n- Supply Quotation status is 'approved'\n- Supplier quotations (quotes) have supplier_approval_status = 'approved'\n- No supplier PO exists yet for all items."
			},
			"response": []
		},
		{
			"name": "2. Get Quotation Details Ready for PO Creation",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{BASE_URL}}/supply/quotations/:quotation_id/supplier-purchase-orders/ready",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"quotations",
						":quotation_id",
						"supplier-purchase-orders",
						"ready"
					],
					"variable": [
						{
							"key": "quotation_id",
							"value": "{{quotation_id}}",
							"description": "Supply Quotation ID"
						}
					]
				},
				"description": "Get full details of a quotation ready for supplier PO creation including:\n- Quotation information\n- Approved supplier quotations grouped by supplier\n- Items with approved quantities\n- Supplier payment methods\n- Items that already have POs"
			},
			"response": []
		},
		{
			"name": "3. Create Single Supplier PO",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"supplier_id\": null,\n    \"items\": [\n        {\n            \"supplier_quote_id\": 1,\n            \"quantity\": 10,\n            \"notes\": \"Standard delivery\"\n        },\n        {\n            \"supplier_quote_id\": 2,\n            \"quantity\": 5,\n            \"notes\": \"Handle with care\"\n        }\n    ],\n    \"expected_start_date\": \"2026-03-01\",\n    \"expected_delivery_date\": \"2026-03-15\",\n    \"receiving_person_id\": 1,\n    \"delivery_notes\": \"Please deliver to warehouse entrance\",\n    \"payment_method\": \"Bank Transfer\",\n    \"discount_amount\": 100.00,\n    \"tax_rate\": 15.0\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/quotations/:quotation_id/supplier-purchase-orders/create-single",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"quotations",
						":quotation_id",
						"supplier-purchase-orders",
						"create-single"
					],
					"variable": [
						{
							"key": "quotation_id",
							"value": "{{quotation_id}}",
							"description": "Supply Quotation ID"
						}
					]
				},
				"description": "Create a single Supplier Purchase Order for all supplier items.\n\n**Validation Rules:**\n- Quotation must be approved\n- All supplier quotes must be approved\n- Quantities cannot exceed approved quotation quantities\n- All required fields must be provided\n\n**Request Body:**\n- `supplier_id` (optional): If not provided, will use supplier from first quote\n- `items[]`: Array of items with supplier_quote_id, quantity, and optional notes\n- `expected_start_date`: Required date\n- `expected_delivery_date`: Required date (must be >= start date)\n- `receiving_person_id`: Required user ID\n- `delivery_notes`: Optional text\n- `payment_method`: Optional (will use supplier's default if not provided)\n- `discount_amount`: Optional decimal\n- `tax_rate`: Optional decimal (0-100)"
			},
			"response": []
		},
		{
			"name": "4. Create Multiple Supplier POs by Delivery Time",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"delivery_groups\": [\n        {\n            \"supplier_id\": null,\n            \"items\": [\n                {\n                    \"supplier_quote_id\": 1,\n                    \"quantity\": 10,\n                    \"notes\": \"Fast delivery items\"\n                }\n            ],\n            \"expected_start_date\": \"2026-03-01\",\n            \"expected_delivery_date\": \"2026-03-05\",\n            \"receiving_person_id\": 1,\n            \"delivery_notes\": \"Urgent delivery\",\n            \"payment_method\": \"Cash\",\n            \"discount_amount\": 50.00,\n            \"tax_rate\": 15.0\n        },\n        {\n            \"supplier_id\": null,\n            \"items\": [\n                {\n                    \"supplier_quote_id\": 2,\n                    \"quantity\": 5,\n                    \"notes\": \"Standard delivery items\"\n                }\n            ],\n            \"expected_start_date\": \"2026-03-10\",\n            \"expected_delivery_date\": \"2026-03-20\",\n            \"receiving_person_id\": 1,\n            \"delivery_notes\": \"Standard delivery\",\n            \"payment_method\": \"Bank Transfer\",\n            \"discount_amount\": 0,\n            \"tax_rate\": 15.0\n        }\n    ],\n    \"expected_start_date\": \"2026-03-01\",\n    \"expected_delivery_date\": \"2026-03-20\",\n    \"receiving_person_id\": 1\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/quotations/:quotation_id/supplier-purchase-orders/create-multiple",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"quotations",
						":quotation_id",
						"supplier-purchase-orders",
						"create-multiple"
					],
					"variable": [
						{
							"key": "quotation_id",
							"value": "{{quotation_id}}",
							"description": "Supply Quotation ID"
						}
					]
				},
				"description": "Create multiple Supplier Purchase Orders grouped by delivery time. Each delivery group will create a separate PO.\n\n**Use Case:**\nWhen items have different delivery times (lead_time_days), you can group them and create separate POs for each delivery time group.\n\n**Request Body:**\n- `delivery_groups[]`: Array of delivery groups, each with:\n  - `supplier_id` (optional)\n  - `items[]`: Array of items\n  - `expected_start_date`: Required for each group\n  - `expected_delivery_date`: Required for each group\n  - `receiving_person_id`: Required for each group\n  - `delivery_notes`: Optional\n  - `payment_method`: Optional\n  - `discount_amount`: Optional\n  - `tax_rate`: Optional\n- Fallback fields (used if not provided in group): `expected_start_date`, `expected_delivery_date`, `receiving_person_id`"
			},
			"response": []
		},
		{
			"name": "5. Create Partial Supplier PO",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"selected_item_ids\": [1, 2],\n    \"supplier_id\": null,\n    \"items\": [\n        {\n            \"supplier_quote_id\": 1,\n            \"quantity\": 10,\n            \"notes\": \"Selected item 1\"\n        },\n        {\n            \"supplier_quote_id\": 2,\n            \"quantity\": 5,\n            \"notes\": \"Selected item 2\"\n        }\n    ],\n    \"expected_start_date\": \"2026-03-01\",\n    \"expected_delivery_date\": \"2026-03-15\",\n    \"receiving_person_id\": 1,\n    \"delivery_notes\": \"Partial order - remaining items will follow\",\n    \"payment_method\": \"Bank Transfer\",\n    \"discount_amount\": 0,\n    \"tax_rate\": 15.0\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/quotations/:quotation_id/supplier-purchase-orders/create-partial",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"quotations",
						":quotation_id",
						"supplier-purchase-orders",
						"create-partial"
					],
					"variable": [
						{
							"key": "quotation_id",
							"value": "{{quotation_id}}",
							"description": "Supply Quotation ID"
						}
					]
				},
				"description": "Create a partial Supplier Purchase Order for only selected items.\n\n**Use Case:**\nWhen you want to create a PO for only some items from the order, not all of them.\n\n**Request Body:**\n- `selected_item_ids[]`: Array of supplier_quote_id values to include in the PO\n- `items[]`: Array of items (must match selected_item_ids)\n- All other fields same as Create Single PO\n\n**Note:** Only items in `selected_item_ids` will be included in the PO."
			},
			"response": []
		},
		{
			"name": "6. Approve Supplier PO Internally",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n    \"notes\": \"Approved by purchasing manager after review\"\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{BASE_URL}}/supply/purchase-orders/:supplier_po_id/approve",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"purchase-orders",
						":supplier_po_id",
						"approve"
					],
					"variable": [
						{
							"key": "supplier_po_id",
							"value": "{{supplier_po_id}}",
							"description": "Supplier Purchase Order ID"
						}
					]
				},
				"description": "Approve a Supplier Purchase Order internally. This changes the `internal_approval_status` to 'approved'.\n\n**Request Body:**\n- `notes` (optional): Approval notes\n\n**Response:**\nReturns the approved PO with updated approval information including `approved_by` and `approved_at`."
			},
			"response": []
		},
		{
			"name": "7. Get Supplier PO Details",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Authorization",
						"value": "Bearer {{access_token}}",
						"type": "text"
					},
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{BASE_URL}}/supply/purchase-orders/:supplier_po_id",
					"host": [
						"{{BASE_URL}}"
					],
					"path": [
						"supply",
						"purchase-orders",
						":supplier_po_id"
					],
					"variable": [
						{
							"key": "supplier_po_id",
							"value": "{{supplier_po_id}}",
							"description": "Supplier Purchase Order ID"
						}
					]
				},
				"description": "Get detailed information about a Supplier Purchase Order including:\n- PO details\n- Supplier information\n- Items with quotation links\n- Delivery details\n- Approval status"
			},
			"response": []
		}
	]
}