{
	"name": "form/nc/erp-sync/4d/save/order-purchase-sales.json",
	"parameter": {
		"show_sql": false
	},
	"save": [
		{
			"record_type": ["sales"],
			"table": "order",
			"all_fields": false,
			"row_table": [{ "table": "order_row", "all_fields": false }],
			"row_number_field-": [
				{
					"field": "ordr.row_number",
					"start_value": 1
				}
			]
		}
	],
	"default_value": {
		"order_row": {
			"copy_value": {
				"info": "description",
				"delivery_date": "ord.json_data.first_delivery_date"
			},
			"static-": {
				"delivery_amount": 0,
				"collected_amount": 0,
				"stock_event_id": "",
				"production_order_id": "",
				"dispatch_note_id": "",
				"invoice_id": ""
			}
		},
		"order": {
			"copy_value": {
				"your_reference": "our_reference",
				"delivery_date": "json_data.first_delivery_date"
			},
			"copy_value-": {
				"json_data.customer_name": "ord.company_id",
				"json_data.project_number": "ord.json_data.project_id"
			},
			"static": {
				"order_type": "TI",
				"order_state": "AV"
			},
			"code": [
				{
					"function": "currentDateString",
					"result": "order_date"
				}
			],
			"code-": [
				{
					"function": "currentUser",
					"result": "create_user"
				}
			]
		}
	},
	"run_script": [
		{
			"table": "order_row",
			"init_new_record": true,
			"find_linked_record": ["ordr.order_id"],
			"script_field": ["ordr.product_id", "ordr.order_amount", "ordr.price_without_vat", "ordr.vat_price", "ordr.unit_price"]
		},
		{
			"table": "order",
			"init_new_record": true,
			"up_calculate": 1,
			"script_field": ["ord.company_id"],
			"script_field-": ["ord.person_id"]
		}
	]
}
