{
	"record_type": [
		"sales",
		"purchase",
		"invoice",
		"dispatch_note"
	],
	"field": [
		{
			"type": "varchar",
			"length": 20,
			"name": "record_type"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "order_id",
			"constraint": [
				"primary key",
				"unique"
			]
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "person_id",
			"foreign_key": {
				"field": "person_id",
				"link_type": "prevent delete",
				"table": "person"
			}
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "currency_id",
			"foreign_key": {
				"field": "currency_id",
				"link_type": "prevent delete",
				"table": "currency"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "terms_of_payment_id",
			"foreign_key": {
				"field": "terms_of_payment_id",
				"link_type": "prevent delete",
				"table": "terms_of_payment"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "company_id",
			"foreign_key": {
				"field": "company_id",
				"link_type": "prevent delete",
				"table": "company"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "delivery_company_id",
			"foreign_key": {
				"field": "company_id",
				"link_type": "prevent delete",
				"table": "company"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "invoicing_company_id",
			"foreign_key": {
				"field": "company_id",
				"link_type": "prevent delete",
				"table": "company"
			}
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "voucher_id",
			"foreign_key": {
				"field": "voucher_id",
				"link_type": "prevent delete",
				"table": "bookkeeping_voucher"
			}
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "project_id"
		},
		{
			"name": "order_address",
			"type": "text"
		},
		{
			"name": "delivery_address",
			"type": "text"
		},
		{
			"name": "invoicing_address",
			"type": "text"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "order_type"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "order_state"
		},
		{
			"name": "order_date",
			"type": "date"
		},
		{
			"name": "confirmation_date",
			"type": "date"
		},
		{
			"name": "due_date",
			"type": "date"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "our_reference"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "your_reference"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "company_reference_number"
		},
		{
			"type": "varchar",
			"length": 120,
			"name": "term_of_delivery"
		},
		{
			"type": "varchar",
			"length": 120,
			"name": "way_of_delivery"
		},
		{
			"name": "discount_price",
			"type": "double"
		},
		{
			"name": "price_without_vat",
			"type": "double"
		},
		{
			"name": "vat_price",
			"type": "double"
		},
		{
			"name": "price_with_vat",
			"type": "double"
		},
		{
			"name": "exchange_rate",
			"type": "double"
		},
		{
			"name": "local_price_without_vat",
			"type": "double"
		},
		{
			"name": "note",
			"type": "text"
		},
		{
			"name": "info",
			"type": "text"
		},
		{
			"name": "json_data",
			"type": "jsonb"
		}
	],
	"constraint": {
		"save": {
			"allow": [
				{
					"field": "ord_order_id",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_order_id",
							"<>",
							""
						]
					]
				},
				{
					"field": "ord_company_id",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_company_id",
							"<>",
							""
						]
					]
				},
				{
					"field": "ord_person_id",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_person_id",
							"<>",
							""
						]
					]
				},
				{
					"field": "ord_currency_id",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_currency_id",
							"<>",
							""
						]
					]
				},
				{
					"field": "ord_terms_of_payment_id",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_terms_of_payment_id",
							"<>",
							""
						]
					]
				},
				{
					"field": "ord_order_type",
					"message": "Field '%s' may not be empty",
					"code": [
						[
							"ord_order_type",
							"<>",
							""
						]
					]
				},
				{
					"message": "Sum of row prices is not same as total price",
					"code": [
						[
							"row_check_price",
							"==",
							0
						],
						"or",
						[
							"row_check_price",
							"==",
							"ord_price_with_vat"
						]
					]
				}
			]
		}
	},
	"table_prefix": "ord",
	"extra_field": [
		{
			"type": "varchar",
			"length": 60,
			"name": "json_data.accounts_ledger"
		},
		{
			"type": "varchar",
			"length": 4,
			"name": "json_data.approval_state"
		},
		{
			"type": "date",
			"name": "json_data.cash_discount_due_date"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.customer_project"
		},
		{
			"type": "double",
			"name": "json_data.debet_total"
		},
		{
			"type": "date",
			"name": "json_data.destination_date"
		},
		{
			"type": "integer",
			"name": "json_data.firm_id"
		},
		{
			"type": "double",
			"name": "json_data.kredit_total"
		},
		{
			"type": "varchar",
			"length": 50,
			"name": "json_data.method_of_payment"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.modifier_id"
		},
		{
			"type": "boolean",
			"name": "json_data.no_bank_program"
		},
		{
			"type": "varchar",
			"length": 30,
			"name": "json_data.note_type"
		},
		{
			"type": "double",
			"name": "json_data.payable_amount"
		},
		{
			"type": "date",
			"name": "json_data.payment_date"
		},
		{
			"type": "integer",
			"name": "json_data.priority"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.project_id"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.purchase_debt_account_id"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.purchase_order_id"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.bank_account"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.bank_reference_number"
		},
		{
			"type": "double",
			"name": "json_data.paid_price"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.intermediator"
		},
		{
			"type": "varchar",
			"length": 120,
			"name": "json_data.transfer_id"
		},
		{
			"type": "integer",
			"name": "json_data.transfer_state"
		},
		{
			"type": "text",
			"name": "json_data.description_of_the_goods"
		},
		{
			"type": "varchar",
			"length": 60,
			"name": "json_data.eur_number"
		},
		{
			"type": "double",
			"name": "json_data.freight_charges"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.freight_charges_payer"
		},
		{
			"type": "double",
			"name": "json_data.gross_weight"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.mark"
		},
		{
			"type": "double",
			"name": "json_data.net_weight"
		},
		{
			"type": "integer",
			"name": "json_data.number_of_pallets"
		},
		{
			"type": "boolean",
			"name": "json_data.printed"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "json_data.pro_forma_number"
		},
		{
			"type": "double",
			"name": "json_data.volume"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.waybill_id"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "json_data.collection_invoice_id"
		},
		{
			"type": "date",
			"name": "json_data.collection_started"
		},
		{
			"type": "double",
			"name": "json_data.coming_price"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "json_data.credit_note"
		},
		{
			"type": "double",
			"name": "json_data.discount_percentage"
		},
		{
			"type": "double",
			"name": "json_data.payment_discount_price"
		},
		{
			"type": "varchar",
			"length": 12,
			"name": "json_data.divided"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.eur_1_no"
		},
		{
			"type": "boolean",
			"name": "json_data.exported_to_ar"
		},
		{
			"type": "text",
			"name": "json_data.footnote"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.handler_id"
		},
		{
			"type": "date",
			"name": "json_data.last_collection_date"
		},
		{
			"type": "double",
			"name": "json_data.order_discount_percentage"
		},
		{
			"type": "double",
			"name": "json_data.order_discount_total"
		},
		{
			"type": "double",
			"name": "json_data.penalty_interest_percent"
		},
		{
			"type": "varchar",
			"length": 70,
			"name": "json_data.remark_time"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.send_state"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.send_type"
		},
		{
			"type": "date",
			"name": "json_data.supplier_invoice_date"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.supplier_invoice_number"
		},
		{
			"type": "double",
			"name": "json_data.rounding_price"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.company_id"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.cost_center"
		},
		{
			"type": "integer",
			"name": "json_data.delivery_to_customer"
		},
		{
			"type": "date",
			"name": "json_data.first_delivery_date"
		},
		{
			"type": "text",
			"name": "json_data.invoicing_address"
		},
		{
			"type": "integer",
			"name": "json_data.invoicing_state"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.receiver_id"
		},
		{
			"type": "date",
			"name": "json_data.shipping_date"
		},
		{
			"type": "integer",
			"name": "json_data.add_packing_cost"
		},
		{
			"type": "integer",
			"name": "json_data.add_packing_material"
		},
		{
			"type": "boolean",
			"name": "json_data.collection_invoice"
		},
		{
			"type": "double",
			"name": "json_data.cost_price"
		},
		{
			"type": "varchar",
			"length": 100,
			"name": "json_data.country_of_destination"
		},
		{
			"type": "varchar",
			"length": 100,
			"name": "json_data.country_of_origin"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.covenant"
		},
		{
			"type": "text",
			"name": "json_data.dealer_address"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.dealer_company_id"
		},
		{
			"type": "varchar",
			"length": 100,
			"name": "json_data.destination"
		},
		{
			"type": "varchar",
			"length": 100,
			"name": "json_data.discharge_place"
		},
		{
			"type": "double",
			"name": "json_data.euro_rate"
		},
		{
			"type": "double",
			"name": "json_data.material_cost"
		},
		{
			"type": "double",
			"name": "json_data.material_margin"
		},
		{
			"type": "double",
			"name": "json_data.material_margin_percentage"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "json_data.offer_number"
		},
		{
			"type": "double",
			"name": "json_data.order_discount"
		},
		{
			"type": "text",
			"name": "json_data.packing_info"
		},
		{
			"type": "integer",
			"name": "json_data.packing_state"
		},
		{
			"type": "varchar",
			"length": 100,
			"name": "json_data.place_of_departure"
		},
		{
			"type": "date",
			"name": "json_data.postcalc_date"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.precarriage"
		},
		{
			"type": "double",
			"name": "json_data.row_discount_percentage"
		},
		{
			"type": "double",
			"name": "json_data.sales_margin"
		},
		{
			"type": "double",
			"name": "json_data.sales_margin_percentage"
		},
		{
			"type": "double",
			"name": "json_data.sales_price_wo_discount"
		},
		{
			"type": "double",
			"name": "json_data.sales_probability"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.supplier_id"
		},
		{
			"type": "date",
			"name": "json_data.supplier_invoicing_date"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.tariff_heading"
		},
		{
			"type": "varchar",
			"length": 70,
			"name": "json_data.your_reference_of_delivery"
		},
		{
			"type": "varchar",
			"length": 70,
			"name": "json_data.your_reference_of_invoice"
		}
	],
	"calculated_field": [
		{
			"type": "double",
			"name": "json_data.discount_price",
			"code": [
				[
					"ord_json_data.discount_price",
					"=",
					[
						"rowSum",
						[
							"ordr_discount_price"
						]
					]
				]
			]
		},
		{
			"type": "double",
			"name": "json_data.paid_price",
			"code": [
				[
					"ord_json_data.paid_price",
					"=",
					[
						"rowSum",
						[
							"invp_paid_price"
						]
					]
				]
			]
		},
		{
			"type": "double",
			"name": "json_data.payment_discount_price",
			"code": [
				[
					"ord_json_data.payment_discount_price",
					"=",
					[
						"rowSum",
						[
							"invp_discount_price"
						]
					]
				]
			]
		},
		{
			"type": "double",
			"name": "price_without_vat",
			"code": [
				[
					"ord_price_without_vat",
					"=",
					[
						"rowSum",
						[
							"ordr_price_without_vat"
						]
					]
				]
			]
		},
		{
			"type": "double",
			"name": "vat_price",
			"code": [
				[
					"ord_vat_price",
					"=",
					[
						"rowSum",
						[
							"ordr_vat_price"
						]
					]
				]
			]
		},
		{
			"type": "double",
			"name": "price_with_vat",
			"code": [
				[
					"ord_price_with_vat",
					"=",
					[
						"ord_price_without_vat",
						"+",
						"ord_vat_price",
						"+",
						"ord_json_data.rounding_price"
					]
				]
			]
		}
	],
	"save_script": [],
	"name": "structure_ma/ord.json",
	"table_name": "order"
}