{
	"info": {
		"_postman_id": "delivery-notes-api-collection",
		"name": "Delivery Notes Management API (v2)",
		"description": "API endpoints for managing delivery notes in the supply chain system.\n\n## Authentication\nAll endpoints require Bearer token authentication.\n\n## Permissions\n- View endpoints: `supply.deliveries.view`\n- Edit endpoints: `supply.deliveries.edit`",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"variable": [
		{
			"key": "orderId",
			"value": "1",
			"type": "string"
		},
		{
			"key": "noteId",
			"value": "1",
			"type": "string"
		}
	],
	"item": [
		{
			"name": "Order-Scoped Routes",
			"description": "Routes scoped to a specific order",
			"item": [
				{
					"name": "Get Items Ready for Delivery",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/items-ready-for-delivery",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"items-ready-for-delivery"
							]
						},
						"description": "Get items from an order that are ready for delivery.\n\n**Permission Required:** `supply.deliveries.view`\n\n**Response:** List of items that can be included in a delivery note."
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "GET",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/items-ready-for-delivery",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"items-ready-for-delivery"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Items ready for delivery retrieved successfully\",\n    \"data\": [\n        {\n            \"supply_order_item_id\": 1,\n            \"product_name\": \"Product A\",\n            \"quantity_ordered\": 100,\n            \"quantity_delivered\": 50,\n            \"quantity_remaining\": 50\n        }\n    ]\n}"
						}
					]
				},
				{
					"name": "List Delivery Notes for Order",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/delivery-notes",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"delivery-notes"
							]
						},
						"description": "List all delivery notes for a specific order.\n\n**Permission Required:** `supply.deliveries.view`"
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "GET",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/delivery-notes",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"delivery-notes"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Delivery notes listed successfully\",\n    \"data\": [\n        {\n            \"id\": 1,\n            \"order_id\": 1,\n            \"delivery_method\": \"direct_pickup\",\n            \"status\": \"awaiting_signature\",\n            \"recipient_name\": \"John Doe\",\n            \"delivery_date\": null,\n            \"notes\": \"Handle with care\",\n            \"created_at\": \"2024-01-15T10:30:00Z\"\n        }\n    ]\n}"
						}
					]
				},
				{
					"name": "Create Delivery Note",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"items\": [\n        {\n            \"supply_order_item_id\": 1,\n            \"quantity_delivered\": 25.5,\n            \"notes\": \"Partial delivery - first batch\"\n        },\n        {\n            \"supply_order_item_id\": 2,\n            \"quantity_delivered\": 100,\n            \"notes\": null\n        }\n    ],\n    \"delivery_method\": \"direct_pickup\",\n    \"recipient_name\": \"Ahmed Mohamed\",\n    \"delivery_date\": null,\n    \"notes\": \"Customer will pick up from warehouse\"\n}"
						},
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/delivery-notes",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"delivery-notes"
							]
						},
						"description": "Create a new delivery note for the order.\n\n**Permission Required:** `supply.deliveries.edit`\n\n## Request Body\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| items | array | Yes | Array of items to deliver (min: 1) |\n| items.*.supply_order_item_id | integer | Yes | ID of the supply order item |\n| items.*.quantity_delivered | numeric | Yes | Quantity being delivered (min: 0.001) |\n| items.*.notes | string | No | Notes for this specific item |\n| delivery_method | string | Yes | One of: `direct_pickup`, `shipping`, `delivery_date` |\n| recipient_name | string | No | Name of the person receiving the delivery |\n| delivery_date | date | Conditional | Required if delivery_method is `delivery_date` |\n| notes | string | No | General notes for the delivery note |"
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/delivery-notes",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"delivery-notes"
									]
								}
							},
							"status": "Created",
							"code": 201,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Delivery note created successfully\",\n    \"data\": {\n        \"id\": 1,\n        \"order_id\": 1,\n        \"delivery_method\": \"direct_pickup\",\n        \"status\": \"awaiting_signature\",\n        \"recipient_name\": \"Ahmed Mohamed\",\n        \"delivery_date\": null,\n        \"notes\": \"Customer will pick up from warehouse\",\n        \"items\": [\n            {\n                \"supply_order_item_id\": 1,\n                \"quantity_delivered\": 25.5,\n                \"notes\": \"Partial delivery - first batch\"\n            }\n        ],\n        \"created_at\": \"2024-01-15T10:30:00Z\"\n    }\n}"
						},
						{
							"name": "Validation Error",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/delivery-notes",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"delivery-notes"
									]
								}
							},
							"status": "Unprocessable Entity",
							"code": 422,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": false,\n    \"message\": \"Validation failed\",\n    \"errors\": {\n        \"items\": [\"يجب اختيار عنصر واحد على الأقل\"],\n        \"delivery_method\": [\"طريقة التسليم مطلوبة\"]\n    }\n}"
						}
					]
				},
				{
					"name": "Create Delivery Note (with Delivery Date)",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"items\": [\n        {\n            \"supply_order_item_id\": 1,\n            \"quantity_delivered\": 50,\n            \"notes\": null\n        }\n    ],\n    \"delivery_method\": \"delivery_date\",\n    \"recipient_name\": \"Warehouse Manager\",\n    \"delivery_date\": \"2024-02-01\",\n    \"notes\": \"Scheduled delivery to main warehouse\"\n}"
						},
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/delivery-notes",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"delivery-notes"
							]
						},
						"description": "Create a delivery note with a scheduled delivery date.\n\n**Note:** When `delivery_method` is `delivery_date`, the `delivery_date` field becomes required."
					},
					"response": []
				},
				{
					"name": "Create Delivery Note (Shipping)",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"items\": [\n        {\n            \"supply_order_item_id\": 3,\n            \"quantity_delivered\": 200,\n            \"notes\": \"Fragile items - pack carefully\"\n        }\n    ],\n    \"delivery_method\": \"shipping\",\n    \"recipient_name\": \"Customer Name\",\n    \"delivery_date\": null,\n    \"notes\": \"Ship via express courier\"\n}"
						},
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/delivery-notes",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"delivery-notes"
							]
						},
						"description": "Create a delivery note for shipping method."
					},
					"response": []
				},
				{
					"name": "Check if Order Can Be Closed",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/supply/orders/{{orderId}}/can-close",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"orders",
								"{{orderId}}",
								"can-close"
							]
						},
						"description": "Check if an order can be closed (all delivery notes must be signed).\n\n**Permission Required:** `supply.deliveries.view`\n\n**Response:** Returns `can_close: true` if all delivery notes are signed, `false` otherwise."
					},
					"response": [
						{
							"name": "Can Close - True",
							"originalRequest": {
								"method": "GET",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/can-close",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"can-close"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Order can be closed\",\n    \"data\": {\n        \"can_close\": true\n    }\n}"
						},
						{
							"name": "Can Close - False",
							"originalRequest": {
								"method": "GET",
								"url": {
									"raw": "{{BASE_URL}}/orders/{{orderId}}/can-close",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"orders",
										"{{orderId}}",
										"can-close"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Order cannot be closed - pending signatures\",\n    \"data\": {\n        \"can_close\": false\n    }\n}"
						}
					]
				}
			]
		},
		{
			"name": "Delivery Note Direct Routes",
			"description": "Routes that operate directly on delivery notes",
			"item": [
				{
					"name": "Show Delivery Note",
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/supply/delivery-notes/{{noteId}}",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"delivery-notes",
								"{{noteId}}"
							]
						},
						"description": "Get details of a single delivery note.\n\n**Permission Required:** `supply.deliveries.view`"
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "GET",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Delivery note retrieved successfully\",\n    \"data\": {\n        \"id\": 1,\n        \"order_id\": 1,\n        \"delivery_method\": \"direct_pickup\",\n        \"status\": \"awaiting_signature\",\n        \"recipient_name\": \"Ahmed Mohamed\",\n        \"delivery_date\": null,\n        \"notes\": \"Customer will pick up from warehouse\",\n        \"signed_document_url\": null,\n        \"items\": [\n            {\n                \"supply_order_item_id\": 1,\n                \"quantity_delivered\": 25.5,\n                \"notes\": \"Partial delivery\"\n            }\n        ],\n        \"created_at\": \"2024-01-15T10:30:00Z\",\n        \"updated_at\": \"2024-01-15T10:30:00Z\"\n    }\n}"
						}
					]
				},
				{
					"name": "Upload Signed Delivery Note",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"body": {
							"mode": "formdata",
							"formdata": [
								{
									"key": "signed_document",
									"description": "Signed delivery note document (PDF, JPG, JPEG, or PNG). Max size: 10MB",
									"type": "file",
									"src": []
								}
							]
						},
						"url": {
							"raw": "{{BASE_URL}}/supply/delivery-notes/{{noteId}}/upload-signed",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"delivery-notes",
								"{{noteId}}",
								"upload-signed"
							]
						},
						"description": "Upload a signed delivery note document and mark the delivery note as approved.\n\n**Permission Required:** `supply.deliveries.edit`\n\n**Prerequisites:** The delivery note must be in `awaiting_signature` status.\n\n## Request Body (multipart/form-data)\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| signed_document | file | Yes | The signed document file |\n\n## Accepted File Types\n- PDF (.pdf)\n- JPEG (.jpg, .jpeg)\n- PNG (.png)\n\n## File Size Limit\n- Maximum: 10MB (10240 KB)"
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}/upload-signed",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}",
										"upload-signed"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Delivery note approved successfully\",\n    \"data\": {\n        \"id\": 1,\n        \"order_id\": 1,\n        \"status\": \"approved\",\n        \"signed_document_url\": \"https://storage.example.com/delivery-notes/signed/note-1.pdf\",\n        \"approved_at\": \"2024-01-16T14:00:00Z\"\n    }\n}"
						},
						{
							"name": "Error - Not Awaiting Signature",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}/upload-signed",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}",
										"upload-signed"
									]
								}
							},
							"status": "Unprocessable Entity",
							"code": 422,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": false,\n    \"message\": \"Delivery note is not awaiting signature\"\n}"
						},
						{
							"name": "Validation Error",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}/upload-signed",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}",
										"upload-signed"
									]
								}
							},
							"status": "Unprocessable Entity",
							"code": 422,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": false,\n    \"message\": \"Validation failed\",\n    \"errors\": {\n        \"signed_document\": [\"يجب رفع إشعار التسليم الموقع\"]\n    }\n}"
						}
					]
				},
				{
					"name": "Cancel Delivery Note",
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "Accept",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{token}}"
							}
						],
						"url": {
							"raw": "{{BASE_URL}}/supply/delivery-notes/{{noteId}}/cancel",
							"host": [
								"{{BASE_URL}}"
							],
							"path": [
								"supply",
								"delivery-notes",
								"{{noteId}}",
								"cancel"
							]
						},
						"description": "Cancel a delivery note and revert the associated item statuses.\n\n**Permission Required:** `supply.deliveries.edit`\n\n**Prerequisites:** The delivery note must be in `awaiting_signature` status. Approved or already cancelled notes cannot be cancelled.\n\n**Side Effects:**\n- The delivery note status will be set to `cancelled`\n- All associated item delivery quantities will be reverted"
					},
					"response": [
						{
							"name": "Success Response",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}/cancel",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}",
										"cancel"
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": true,\n    \"message\": \"Delivery note cancelled successfully\",\n    \"data\": {\n        \"id\": 1,\n        \"order_id\": 1,\n        \"status\": \"cancelled\",\n        \"cancelled_at\": \"2024-01-16T14:00:00Z\"\n    }\n}"
						},
						{
							"name": "Error - Cannot Cancel",
							"originalRequest": {
								"method": "POST",
								"url": {
									"raw": "{{BASE_URL}}/delivery-notes/{{noteId}}/cancel",
									"host": [
										"{{BASE_URL}}"
									],
									"path": [
										"delivery-notes",
										"{{noteId}}",
										"cancel"
									]
								}
							},
							"status": "Unprocessable Entity",
							"code": 422,
							"_postman_previewlanguage": "json",
							"body": "{\n    \"success\": false,\n    \"message\": \"Delivery note cannot be cancelled\"\n}"
						}
					]
				}
			]
		}
	],
	"auth": {
		"type": "bearer",
		"bearer": [
			{
				"key": "token",
				"value": "{{token}}",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	]
}
