{
	"$schema": "http://json-schema.org/draft-03/schema#",
	"title": "Draft order schema",
	"description": "A schema for retrieving a draft order.",
	"type": "object",
	"restdocs": "http://restdocs.e-conomic.com/#get-orders-drafts-ordernumber",
	"properties": {
		"orderNumber": {
			"type": "integer",
			"minimum": 1,
			"maximum": 999999999,
			"filterable": true,
			"sortable": true,
			"description": "A reference number for the order document."
		},
		"date": {
			"type": "string",
			"format": "full-date",
			"pattern": "\\d{4}-\\d{2}-\\d{2}",
			"filterable": true,
			"sortable": true,
			"description": "Order issue date. Format according to ISO-8601 (YYYY-MM-DD)."
		},
		"currency": {
			"type": "string",
			"pattern": "[a-zA-Z]{3}",
			"filterable": true,
			"sortable": true,
			"description": "The ISO 4217 currency code of the order."
		},
		"exchangeRate": {
			"type": "number",
			"filterable": true,
			"sortable": true,
			"maxDecimal": 6,
			"description": "The exchange rate between the order currency and the base currency of the agreement. The exchange rate expresses how much it will cost in base currency to buy 100 units of the order currency."
		},
		"netAmount": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total order amount in the order currency before all taxes and discounts have been applied."
		},
		"netAmountInBaseCurrency": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total order amount in the base currency of the agreement before all taxes and discounts have been applied."
		},
		"grossAmount": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total order amount in the order currency after all taxes and discounts have been applied."
		},
		"grossAmountInBaseCurrency": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total order amount in the base currency of the agreement after all taxes and discounts have been applied."
		},
		"marginInBaseCurrency": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The difference between the cost price of the items on the order and the sales net order amount in base currency."
		},
		"marginPercentage": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The margin expressed as a percentage. If the net order amount is less than the cost price this number will be negative."
		},
		"vatAmount": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total amount of VAT on the order in the order currency. This will have the same sign as net amount"
		},
		"roundingAmount": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total rounding error, if any, on the order in base currency."
		},
		"costPriceInBaseCurrency": {
			"type": "number",
			"maxDecimal": 2,
			"description": "The total cost of the items on the order in the base currency of the agreement."
		},
		"dueDate": {
			"type": "string",
			"format": "full-date",
			"pattern": "\\d{4}-\\d{2}-\\d{2}",
			"description": "The date the order, is due for payment. Format according to ISO-8601 (YYYY-MM-DD). This is only used if the terms of payment is of type 'duedate'."
		},
		"attachment": {
			"type": "string",
			"format": "uri",
			"description": "A unique reference to the attachment file on the given draft order."
		},
		"layout": {
			"type": "object",
			"description": "Layout to be applied for draft orders and other documents for this customer.",
			"properties": {
				"layoutNumber": {
					"type": "integer",
					"description": "The unique identifier of the layout."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "A unique link reference to the layout item.",
					"required": true
				}
			}
		},
		"paymentTerms": {
			"type": "object",
			"description": "The terms of payment for the order.",
			"properties": {
				"paymentTermsNumber": {
					"type": "integer",
					"minimum": 0,
					"exclusiveMinimum": true,
					"filterable": true,
					"sortable": true,
					"description": "A unique identifier of the payment term."
				},
				"daysOfCredit": {
					"type": "integer",
					"minimum": 0,
					"description": "The number of days of credit on the order. This field is only valid if terms of payment is not of type duedate."
				},
				"name": {
					"type": "string",
					"maxLength": 50,
					"description": "The name of the payment terms."
				},
				"paymentTermsType": {
					"enum": [ "net", "invoiceMonth", "paidInCash", "prepaid", "dueDate", "factoring", "invoiceWeekStartingSunday", "invoiceWeekStartingMonday", "creditcard" ],
					"description": "The type of payment term."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "A unique reference to the payment term resource.",
					"required": true
				}
			}
		},
		"customer": {
			"type": "object",
			"description": "The customer of the order.",
			"properties": {
				"customerNumber": {
					"type": "integer",
					"maximum": 999999999,
					"minimum": 1,
					"filterable": true,
					"sortable": true,
					"description": "The customer id number. The customer id number can be either positive or negative, but it can't be zero."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "A unique reference to the customer resource.",
					"required": true
				}
			}
		},
		"recipient": {
			"type": "object",
			"description": "The actual recipient of the order. This may be the same info found on the customer (and will probably be so in most cases) but it may also be a different recipient. For instance, the customer placing the order may be ACME Headquarters, but the recipient of the order may be ACME IT.",
			"properties": {
				"name": {
					"type": "string",
					"maxLength": 250,
					"filterable": true,
					"sortable": true,
					"description": "The name of the actual recipient."
				},
				"address": {
					"type": "string",
					"maxLength": 250,
					"filterable": true,
					"sortable": true,
					"description": "The street address of the actual recipient."
				},
				"zip": {
					"type": "string",
					"maxLength": 50,
					"filterable": true,
					"sortable": true,
					"description": "The zip code of the actual recipient."
				},
				"city": {
					"type": "string",
					"maxLength": 250,
					"filterable": true,
					"sortable": true,
					"description": "The city of the actual recipient."
				},
				"country": {
					"type": "string",
					"maxLength": 50,
					"filterable": true,
					"sortable": true,
					"description": "The country of the actual recipient."
				},
				"ean": {
					"type": "string",
					"maxLength": 13,
					"filterable": true,
					"sortable": true,
					"description": "The 'European Article Number' of the actual recipient."
				},
				"publicEntryNumber": {
					"type": "string",
					"maxLength": 40,
					"filterable": true,
					"sortable": true,
					"description": "The public entry number of the actual recipient."
				},
				"attention": {
					"type": "object",
					"description": "The person to whom this order is addressed.",
					"properties": {
						"customerContactNumber": {
							"type": "integer",
							"description": "Unique identifier of the customer employee."
						},
						"self": {
							"type": "string",
							"format": "uri",
							"description": "A unique reference to the customer employee.",
							"required": true
						}
					}
				},
				"vatZone": {
					"type": "object",
					"description": "Recipient vat zone.",
					"properties": {
						"vatZoneNumber": {
							"type": "integer",
							"description": "Unique identifier of the vat zone."
						},
						"self": {
							"type": "string",
							"format": "uri",
							"description": "A unique reference to the vat zone.",
							"required": true
						}
					}
				},
				"cvr": {
					"type": "string",
					"description": "The Corporate Identification Number of the recipient for example CVR in Denmark.",
					"maxLength": 40
				},
				"nemHandelType": {
					"enum": [ "ean", "corporateIdentificationNumber", "pNumber", "peppol", null ],
					"description": "Chosen NemHandel type used for e-invoicing."
				}
			}
		},
		"deliveryLocation": {
			"type": "object",
			"description": "A reference to the place of delivery for the goods on the order",
			"properties": {
				"deliveryLocationNumber": {
					"type": "integer",
					"filterable": true,
					"sortable": true,
					"description": "A unique identifier for the delivery location."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "A unique reference to the delivery location resource.",
					"required": true
				}
			}
		},
		"delivery": {
			"type": "object",
			"description": "The actual place of delivery for the goods on the order. This is usually the same place as the one referenced in the deliveryLocation property, but may be edited as required.",
			"properties": {
				"address": {
					"type": "string",
					"maxLength": 255,
					"filterable": true,
					"sortable": true,
					"description": "Street address where the goods must be delivered to the customer."
				},
				"zip": {
					"type": "string",
					"maxLength": 30,
					"filterable": true,
					"sortable": true,
					"description": "The zip code of the place of delivery."
				},
				"city": {
					"type": "string",
					"maxLength": 50,
					"filterable": true,
					"sortable": true,
					"description": "The city of the place of delivery"
				},
				"country": {
					"type": "string",
					"maxLength": 50,
					"filterable": true,
					"sortable": true,
					"description": "The country of the place of delivery"
				},
				"deliveryTerms": {
					"type": "string",
					"maxLength": 100,
					"filterable": true,
					"sortable": true,
					"description": "Details about the terms of delivery."
				},
				"deliveryDate": {
					"type": "string",
					"format": "full-date",
					"pattern": "\\d{4}-\\d{2}-\\d{2}",
					"filterable": true,
					"sortable": true,
					"description": "The date of delivery."
				}
			}
		},
		"notes": {
			"type": "object",
			"description": "Notes on the order.",
			"properties": {
				"heading": {
					"type": "string",
					"maxLength": 250,
					"filterable": true,
					"sortable": true,
					"description": "The order heading. Usually displayed at the top of the order."
				},
				"textLine1": {
					"type": "string",
					"maxLength": 1000,
					"filterable": true,
					"sortable": true,
					"description": "The first line of supplementary text on the order. This is usually displayed right under the heading in a smaller font."
				},
				"textLine2": {
					"type": "string",
					"maxLength": 1000,
					"filterable": true,
					"sortable": true,
					"description": "The second line of supplementary text in the notes on the order. This is usually displayed as a footer on the order."
				}
			}
		},
		"references": {
			"type": "object",
			"description": "Customer and company references related to this order.",
			"properties": {
				"customerContact": {
					"type": "object",
					"description": "The customer contact is a reference to the employee at the customer to contact regarding the order.",
					"properties": {
						"customerContactNumber": {
							"type": "integer",
							"minimum": 0,
							"exclusiveMinimum": true,
							"description": "Unique identifier of the customer contact."
						},
						"customer": {
							"type": "object",
							"description": "The customer this contact belongs to.",
							"properties": {
								"customerNumber": {
									"type": "integer",
									"maximum": 999999999,
									"minimum": 1,
									"filterable": true,
									"sortable": true,
									"description": "The customer id number. The customer id number can be either positive or negative, but it can't be zero."
								},
								"self": {
									"type": "string",
									"format": "uri",
									"description": "A unique reference to the customer resource.",
									"required": true
								}
							}
						},
						"self": {
							"type": "string",
							"format": "uri",
							"description": "A unique reference to the customer contact resource.",
							"required": true
						}
					}
				},
				"salesPerson": {
					"type": "object",
					"description": "The sales person is a reference to the employee who sold the goods on the order. This is also the person who is credited with this sale in reports.",
					"properties": {
						"employeeNumber": {
							"type": "integer",
							"minimum": 1,
							"filterable": true,
							"sortable": true,
							"description": "Unique identifier of the employee."
						},
						"self": {
							"type": "string",
							"format": "uri",
							"description": "A unique reference to the employee resource.",
							"required": true
						}
					}
				},
				"vendorReference": {
					"type": "object",
					"description": "A reference to any second employee involved in the sale.",
					"properties": {
						"employeeNumber": {
							"type": "integer",
							"minimum": 1,
							"filterable": true,
							"sortable": true,
							"description": "Unique identifier of the employee."
						},
						"self": {
							"type": "string",
							"format": "uri",
							"description": "A unique reference to the employee resource.",
							"required": true
						}
					}
				},
				"other": {
					"type": "string",
					"maxLength": 250,
					"filterable": true,
					"sortable": true,
					"description": "A text field that can be used to save any custom reference on the order."
				}
			}
		},
		"project": {
			"type": "object",
			"description": "The project the order is connected to.",
			"properties": {
				"projectNumber": {
					"type": "integer",
					"minimum": 1,
					"description": "A unique identifier of the project."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "A unique reference to the project resource.",
					"required": true
				}
			}
		},
		"lastUpdated": {
			"type": "string",
			"format": "full-date",
			"pattern": "\\d{4}-\\d{2}-\\d{2}Td{2}:d{2}:d{2}Z",
			"filterable": true,
			"readOnly": true,
			"description": "The last time the order was updated. The date is formatted according to ISO-8601."
		},
		"pdf": {
			"type": "object",
			"description": "References a pdf representation of this order.",
			"properties": {
				"download": {
					"type": "string",
					"format": "uri",
					"description": "The unique reference of the pdf representation for this order."
				}
			}
		},
		"soap": {
			"type": "object",
			"description": "References a SOAP order handle.",
			"properties": {
				"orderHandle": {
					"type": "object",
					"description": "The unique reference of the SOAP order handle.",
					"properties": {
						"id": {
							"type": "integer",
							"description": "ID of the SOAP order handle.",
							"filterable": true,
							"sortable": true
						}
					}
				}
			}
		},
		"templates": {
			"type": "object",
			"description": "References to all templates on this order.",
			"readonly": true,
			"properties": {
				"upgradeInstructions": {
					"type": "string",
					"format": "uri",
					"description": "The self reference to the document to POST to /invoices/drafts to upgrade the order to an invoice draft."
				},
				"self": {
					"type": "string",
					"format": "uri",
					"description": "The self reference to the order templates resource.",
					"required": true
				}
			}
		},
		"lines": {
			"title": "Order lines",
			"type": "array",
			"description": "An array containing the specific order lines.",
			"items": {
				"type": "object",
				"description": "An array of the order lines that make up the order.",
				"properties": {
					"lineNumber": {
						"type": "integer",
						"description": "The line number is a unique number within the order.",
						"minimum": 0,
						"exclusiveMinimum": true
					},
					"sortKey": {
						"type": "integer",
						"description": "A sort key used to sort the lines in ascending order within the order.",
						"minimum": 0,
						"exclusiveMinimum": true
					},
					"description": {
						"type": "string",
						"maxLength": 2500,
						"description": "A description of the product or service sold."
					},
					"accrual": {
						"type": "object",
						"description": "Accrual is used to allocate costs and/or revenues over several periods.",
						"properties": {
							"startDate": {
								"type": "string",
								"format": "full-date",
								"pattern": "\\d{4}-\\d{2}-\\d{2}",
								"description": "The start date for the accrual. Format: YYYY-MM-DD."
							},
							"endDate": {
								"type": "string",
								"format": "full-date",
								"pattern": "\\d{4}-\\d{2}-\\d{2}",
								"description": "The end date for the accrual. Format: YYYY-MM-DD."
							}
						}
					},
					"unit": {
						"type": "object",
						"description": "The unit of measure applied to the order line.",
						"properties": {
							"unitNumber": {
								"type": "integer",
								"description": "The unique identifier of the unit.",
								"minimum": 0,
								"exclusiveMinimum": true
							},
							"name": {
								"type": "string",
								"required": true,
								"maxLength": 100,
								"description": "The name of the unit (e.g. 'kg' for weight or 'l' for volume)."
							},
							"self": {
								"type": "string",
								"format": "uri",
								"description": "A unique reference to the unit resource.",
								"required": true
							}
						}
					},
					"product": {
						"type": "object",
						"description": "The product or service offered on the order line.",
						"properties": {
							"productNumber": {
								"type": "string",
								"maxLength": 25,
								"description": "The unique product number. This can be a stock keeping unit identifier (SKU)."
							},
							"self": {
								"type": "string",
								"format": "uri",
								"description": "A unique reference to the product resource.",
								"required": true
							}
						}
					},
					"quantity": {
						"type": "number",
						"minimum": 0.01,
						"maximum": 999999999999999999,
						"maxDecimal": 2,
						"description": "The number of units of goods on the order line."
					},
					"unitNetPrice": {
						"type": "number",
						"maxDecimal": 2,
						"description": "The price of 1 unit of the goods or services on the order line in the order currency."
					},
					"discountPercentage": {
						"type": "number",
						"maxDecimal": 2,
						"description": "A line discount expressed as a percentage."
					},
					"unitCostPrice": {
						"type": "number",
						"maxDecimal": 2,
						"description": "The cost price of 1 unit of the goods or services in the order currency."
					},
					"totalNetAmount": {
						"type": "number",
						"maxDecimal": 2,
						"description": "The total net amount on the order line in the order currency."
					},
					"marginInBaseCurrency": {
						"type": "number",
						"maxDecimal": 2,
						"description": "The difference between the net price and the cost price on the order line in base currency."
					},
					"marginPercentage": {
						"type": "number",
						"maxDecimal": 2,
						"description": "The margin on the order line expressed as a percentage."
					},
					"departmentalDistribution": {
						"type": "object",
						"description": "A departmental distribution defines which departments this entry is distributed between. This requires the departments module to be enabled.",
						"properties": {
							"departmentalDistributionNumber": {
								"type": "integer",
								"minimum": 1,
								"description": "A unique identifier of the departmental distribution."
							},
							"distributionType": {
								"type": "string",
								"description": "Type of the distribution"
							},
							"self": {
								"type": "string",
								"format": "uri",
								"description": "A unique reference to the departmental distribution resource.",
								"required": true
							}
						}
					}
				}
			}
		},
		"self": {
			"type": "string",
			"format": "uri",
			"description": "The unique self reference of the draft order.",
			"required": true
		}
	}
}
