{
	"name": "save/manager/order/order/webstore/save_to_erp.json",
	"table": [
		{
			"table": "order",
			"record_type": "sales",
			"row_table": ["order_row"],
			"data_structure": "structure",
			"row_number_field": [
				{
					"field": "ordr.row_number",
					"start_value": 1
				}
			]
		}
	],
	"parameter": {
		"show_sql": true
	},
	"default_value": {
		"order": {
			"code": [
				{
					"function": "concatWith",
					"parameter": [
						"\n",
						{
							"tag": "json_data.meta_data[?key=='_woo_carrier_agent_meta'].value[?carrier=='matkahuolto'].title"
						},
						{
							"tag": "json_data.meta_data[?key=='_woo_carrier_agent_meta'].value[?carrier=='matkahuolto'].street_address"
						},
						{
							"tag": "json_data.meta_data[?key=='_woo_carrier_agent_meta'].value[?carrier=='matkahuolto'].street_address2"
						},
						{
							"function": "concatWith",
							"parameter": [
								" ",
								{
									"tag": "json_data.meta_data[?key=='_woo_carrier_agent_meta'].value[?carrier=='matkahuolto'].postcode"
								},
								{
									"tag": "json_data.meta_data[?key=='_woo_carrier_agent_meta'].value[?carrier=='matkahuolto'].city"
								}
							]
						}
					],
					"result": "delivery_address"
				},
				{
					"function": "concatWith",
					"parameter": [
						"\n",
						{
							"function": "concatWith",
							"parameter": [
								" ",
								{
									"tag": "json_data.shipping.last_name"
								},
								{
									"tag": "json_data.shipping.first_name"
								}
							]
						},
						{
							"tag": "json_data.shipping.company"
						},
						{
							"tag": "json_data.shipping.address_1"
						},
						{
							"tag": "json_data.shipping.address_2"
						},
						{
							"function": "concatWith",
							"parameter": [
								" ",
								{
									"tag": "json_data.shipping.postcode"
								},
								{
									"tag": "json_data.shipping.city"
								}
							]
						},
						{
							"tag": "json_data.shipping.email"
						}
					],
					"result": "order_address"
				},
				{
					"function": "concatWith",
					"parameter": [
						"\n",
						{
							"function": "concatWith",
							"parameter": [
								" ",
								{
									"tag": "json_data.billing.last_name"
								},
								{
									"tag": "json_data.billing.first_name"
								}
							]
						},
						{
							"tag": "json_data.billing.company"
						},
						{
							"tag": "json_data.billing.address_1"
						},
						{
							"tag": "json_data.billing.address_2"
						},
						{
							"function": "concatWith",
							"parameter": [
								" ",
								{
									"tag": "json_data.billing.postcode"
								},
								{
									"tag": "json_data.billing.city"
								}
							]
						},
						{
							"function": "concatWith",
							"parameter": [
								", ",
								{
									"tag": "json_data.billing.phone"
								},
								{
									"tag": "json_data.billing.email"
								}
							]
						}
					],
					"result": "invoicing_address"
				}
			],
			"static": {
				"company_id": "7000",
				"order_state": "AV",
				"person_id": "HV",
				"terms_of_payment_id": "K"
			},
			"tag": {
				"company_reference_number": "project_id"
			}
		},
		"order_row": {
			"code": [
				{
					"function": "uppercase",
					"parameter": [
						{
							"tag": "product_id"
						}
					],
					"result": "product_id"
				}
			]
		}
	},
	"run_script": [
		{
			"find_linked_record": ["ordr.order_id"],
			"init_new_record": true,
			"script_field": [
				"ordr.product_id",
				"ordr.order_amount",
				"ordr.unit_price",
				"ordr.price_without_vat",
				"ordr.vat_price"
			],
			"table": "order_row"
		},
		{
			"init_new_record": false,
			"script_field": ["ord.company_id", "ord.person_id"],
			"table": "order",
			"up_calculate": true
		}
	]
}
