{
	"name": "table/local/product/product_work.json",
	"table_name": "product_work",
	"table_prefix": "prwo",
	"main_table": "product",
	"record_type": ["actual", "estimated", "schedule", "nesting"],
	"table_name_language": {
		"actual": "Actual work phase",
		"estimated": "Estimated work phase",
		"schedule": "Scheduled work phase",
		"nesting": "Nesting"
	},
	"default_field": "table/prf/default_field.json",
	"default_order": [
		{
			"field": "production_order_id",
			"order": ">"
		},
		{
			"field": "work_phase_number",
			"order": ">"
		}
	],
	"save_script": [],
	"calculated_field": {
		"can_be_manufactured": {
			"info": "calculate how many can be manufactured from previous phase finished and available materials",
			"type": "text"
		},
		"production_order_schedule_id": {
			"info": "link between work_phase_actual and production_order_schedule",
			"type": "text",
			"code": ["concat", ["prwo.production_order_id", "#", "prwo.work_phase_number"]],
			"foreign_key": [
				{
					"link_type": "do nothing",
					"linked_record_type": "schedule",
					"linking_record_type": "actual"
				}
			]
		},
		"units_in_hour": {
			"type": "double",
			"code": [["prwo.units_in_hour", "=", [1, "/", "prwo.work_hours"]]],
			"run_script": ["prwo.units_in_hour", "prwo.work_hours"],
			"script": [["prwo.work_hours", "=", [1, "/", "prwo.units_in_hour"]], ["prwo_C_KENTAT"]]
		}
	},
	"field": [
		{
			"field_name": "resource_id",
			"field_type": "varchar",
			"field_length": 40,
			"constraint": {
				"save": {
					"allow": [
						{
							"code": [["prwo.resource_id", "<>", ""]],
							"message": "field '%s' may not be empty"
						}
					]
				}
			},
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "resource_id",
					"linked_record_type": "",
					"linked_table": "resource",
					"linking_record_type": ""
				}
			]
		},
		{
			"field_name": "person_id",
			"field_type": "varchar",
			"field_length": 80,
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "person_id",
					"linked_record_type": "",
					"linked_table": "person",
					"linking_record_type": ""
				}
			]
		},
		{
			"field_name": "product_id",
			"field_type": "varchar",
			"field_length": 80,
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "product_id",
					"linked_record_type": "",
					"linked_table": "product",
					"linking_record_type": ""
				},
				{
					"info": "aga, check 1",
					"link_type": "prevent delete",
					"linked_field": "product_id",
					"linked_record_type": "estimated",
					"linked_table": "product_work",
					"linking_record_type": "actual"
				},
				{
					"info": "aga, check 2",
					"link_type": "prevent delete",
					"linked_field": "product_id",
					"linked_record_type": "schedule",
					"linked_table": "product_work",
					"linking_record_type": "actual"
				}
			]
		},
		{
			"field_name": "production_order_id",
			"field_type": "varchar",
			"field_length": 40,
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "production_order_id",
					"linked_record_type": "",
					"linked_table": "production_order",
					"linking_record_type": ""
				}
			]
		},
		{
			"field_name": "work_phase_number",
			"field_type": "integer"
		},
		{
			"field_name": "work_phase_state",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "active_state",
			"field_type": "varchar",
			"field_length": 40,
			"allowed_value": "plugin/nc-calc-server/constant.json/active_state_allowed_value"
		},
		{
			"field_name": "serie",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "start_time",
			"field_type": "timestamp"
		},
		{
			"field_name": "end_time",
			"field_type": "timestamp"
		},
		{
			"field_name": "started_amount",
			"field_type": "double"
		},
		{
			"field_name": "produced_amount",
			"field_type": "double"
		},
		{
			"field_name": "failed_amount",
			"field_type": "double"
		},
		{
			"field_name": "work_hours",
			"field_type": "double"
		},
		{
			"field_name": "setup_hours",
			"field_type": "double"
		},
		{
			"field_name": "machine_hours",
			"field_type": "double"
		},
		{
			"field_name": "extra_hours",
			"field_type": "double"
		},
		{
			"field_name": "description",
			"field_type": "text"
		},
		{
			"field_name": "info",
			"field_type": "text"
		},
		{
			"field_name": "path_id",
			"field_type": "uuid",
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "record_id",
					"linked_record_type": "",
					"linked_table": "production_path"
				}
			]
		},
		{
			"field_name": "subcontract",
			"field_type": "integer",
			"info": "todo: use paths, create estimated_subcontract table"
		},
		{
			"field_name": "subcontractor_id",
			"field_type": "varchar",
			"field_length": 40,
			"foreign_key": [
				{
					"link_type": "prevent delete",
					"linked_field": "company_id",
					"linked_record_type": "",
					"linked_table": "company",
					"linking_record_type": ""
				}
			],
			"nullable": true,
			"info": "todo: use paths, create estimated_subcontract table"
		},
		{
			"field_name": "profit_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "cost_price",
			"field_type": "double"
		},
		{
			"field_name": "sales_price",
			"field_type": "double"
		},
		{
			"field_name": "salary",
			"field_type": "double",
			"info": "TODO: all these pointing to price_history"
		},
		{
			"field_name": "setup_hourly_salary",
			"field_type": "double"
		},
		{
			"field_name": "setup_hourly_self_cost",
			"field_type": "double"
		},
		{
			"field_name": "work_hourly_salary",
			"field_type": "double"
		},
		{
			"field_name": "work_hourly_self_cost",
			"field_type": "double"
		}
	],
	"extra_field": [
		{
			"field_name": "json_data.can_be_manufactured",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.work_phase_type",
			"field_type": "varchar",
			"field_length": 40,
			"info": "renamed to json_data"
		},
		{
			"field_name": "json_data.product_work_state",
			"field_type": "varchar",
			"field_length": 40,
			"allowed_value": "plugin/nc-calc-server/constant.json/phase_state",
			"info": "renamed to json_data"
		},
		{
			"field_name": "json_data.manufacturing_state",
			"field_type": "integer",
			"info": "renamed to json_dat, related to can_be_manufactured"
		},
		{
			"field_name": "json_data.remaining_amount",
			"field_type": "double",
			"info": "renamed to json_data"
		},
		{
			"field_name": "json_data.extra_end_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.est_contract_price__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.track_time_status",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.evening_work_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.social_cost_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "json_data.kind",
			"field_type": "double"
		},
		{
			"field_name": "json_data.rest_time__hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.est_setup_salary__hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.user_id",
			"field_type": "varchar",
			"field_length": 24
		},
		{
			"field_name": "json_data.firm_id",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.next_phase",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.reclamation_count",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.est_work_time__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.delay",
			"field_type": "double"
		},
		{
			"field_name": "json_data.employee_number",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.employee_id",
			"field_type": "varchar",
			"field_length": 24
		},
		{
			"field_name": "json_data.critical_end_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.est_machine_setup_cost__hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.subcont_cost_total",
			"field_type": "double"
		},
		{
			"field_name": "json_data.purchase_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "json_data.target_machine_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.planned_work_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.contract_default_salary",
			"field_type": "double"
		},
		{
			"field_name": "json_data.program_id",
			"field_type": "varchar",
			"field_length": 200
		},
		{
			"field_name": "json_data.transfer_state",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.work_sales_price_total",
			"field_type": "double"
		},
		{
			"field_name": "json_data.critical_start_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.work_cost_total",
			"field_type": "double"
		},
		{
			"field_name": "json_data.start_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.start_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.end_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.salary_amount",
			"field_type": "double"
		},
		{
			"field_name": "json_data.salary_code",
			"field_type": "text"
		},
		{
			"field_name": "json_data.prod_lot__linked_phase",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.subcontract_purchase_price",
			"field_type": "double"
		},
		{
			"field_name": "json_data.setup_amount",
			"field_type": "double"
		},
		{
			"field_name": "json_data.stock_event_id",
			"field_type": "varchar",
			"field_length": 20
		},
		{
			"field_name": "json_data.load_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "json_data.project_id",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.subc_profit_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "json_data.contract_price__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.parcel_code",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.units_in_hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.speed_in_unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.critical_extra_end_time",
			"field_type": "time"
		},
		{
			"field_name": "json_data.unpaid_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.subcont_sales_price_total",
			"field_type": "double"
		},
		{
			"field_name": "json_data.critical_delayed_start_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.delivery_to_customer",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.subcont_cost__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.customer_project",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.phase_number",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.est_bonus_work_time__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.work_time__lot",
			"field_type": "double"
		},
		{
			"field_name": "json_data.est_salary__hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.link_target",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.contract_salary",
			"field_type": "boolean"
		},
		{
			"field_name": "json_data.salary_bonus",
			"field_type": "double"
		},
		{
			"field_name": "json_data.work_salary__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.work_shift",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.link_to_start",
			"field_type": "boolean"
		},
		{
			"field_name": "json_data.run_amount",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.urgency_index",
			"field_type": "double"
		},
		{
			"field_name": "json_data.hourly_salary",
			"field_type": "boolean"
		},
		{
			"field_name": "json_data.target_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.work__position_num_id",
			"field_type": "varchar",
			"field_length": 60
		},
		{
			"field_name": "json_data.transfer_id",
			"field_type": "varchar",
			"field_length": 120
		},
		{
			"field_name": "json_data.track_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.start_work_shift",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.target_extra_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.production_lot__work_ph",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.bonus_work_time__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.tag",
			"field_type": "varchar",
			"field_length": 160
		},
		{
			"field_name": "json_data.supplier_id",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "json_data.substate",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "json_data.subcont_sales_price__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.target_extra_time__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.start_subtype",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "json_data.start_person_id",
			"field_type": "varchar",
			"field_length": 24
		},
		{
			"field_name": "json_data.special_extra_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.critical_delayed_end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.pieces__unit",
			"field_type": "double"
		},
		{
			"field_name": "json_data.night_work_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.critical_date_difference",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.work_phase_actual_id",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.measured_track_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.cost_center",
			"field_type": "varchar",
			"field_length": 40
		},
		{
			"field_name": "json_data.est_machine_work_cost__hour",
			"field_type": "double"
		},
		{
			"field_name": "json_data.act_end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.previous_phase",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.cover__inside",
			"field_type": "varchar",
			"field_length": 4
		},
		{
			"field_name": "json_data.linking_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.advance",
			"field_type": "double"
		},
		{
			"field_name": "json_data.material_owner",
			"field_type": "integer"
		},
		{
			"field_name": "json_data.material_batch",
			"field_type": "varchar",
			"field_length": 80
		},
		{
			"field_name": "json_data.contract_multiplier",
			"field_type": "double"
		},
		{
			"field_name": "json_data.extra_end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.critical_end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.critical_extra_end_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.critical_start_date",
			"field_type": "date"
		},
		{
			"field_name": "json_data.est_setup_hours",
			"field_type": "double"
		},
		{
			"field_name": "json_data.previous_track_time",
			"field_type": "double"
		},
		{
			"field_name": "json_data.additional_data",
			"field_type": "text"
		}
	],
	"field_change": [
		{
			"name": "start_time",
			"old_name": ["event_time"]
		},
		{
			"name": "json_data.product_work_state",
			"old_name": ["record_state"]
		},
		{
			"name": "production_lot",
			"old_name": ["production_order_id"]
		},
		{
			"name": "path_id",
			"old_name": ["route_id"]
		},
		{
			"name": "",
			"old_name": ["event_time"]
		}
	]
}
