{
	"name": "table/manager/product/product_work.json",
	"table_name": "product_work",
	"table_prefix": "prwo",
	"relation": [{
			"linked": {
				"field": "company_id",
				"record_type": "customer",
				"table": "company"
			},
			"info": "link between work_phase and customer via production_order",
			"linking": {
				"field": "company_id",
				"record_type": "schedule",
				"field_via": {
					"field": "company_id",
					"table": "production_order"
				}
			}
		},
		{
			"linked": {
				"field": "production_lot",
				"code": [
					"concat",
					[
						"prwo_production_lot",
						"#",
						"prwo_work_phase_number"
					]
				],
				"record_type": "schedule",
				"table": "product_work"
			},
			"info": "link between work_phase_actual and production_order_schedule",
			"linking": {
				"field": "production_order_schedule_id",
				"record_type": "actual",
				"field_via": {
					"code": [
						"concat",
						[
							"prwo_production_lot",
							"#",
							"prwo_work_phase_number"
						]
					]
				}
			}
		},
		{
			"linked": {
				"field": "product_id",
				"record_type": "estimated",
				"table": "product_work"
			},
			"info": "link between work_phase_actual and work_phase_estimated",
			"linking": {
				"record_type": "actual",
				"field": "product_id"
			}
		}
	],
	"save_script": [],
	"field": [
		{
			"type": "varchar",
			"length": 20,
			"name": "record_type"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "product_id",
			"foreign_key": {
				"field": "product_id",
				"link_type": "prevent delete",
				"table": "product"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "production_lot",
			"foreign_key": {
				"field": "production_lot",
				"link_type": "prevent delete",
				"table": "production_order"
			}
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "resource_id",
			"foreign_key": {
				"field": "resource_id",
				"link_type": "prevent delete",
				"table": "resource"
			}
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "person_id",
			"foreign_key": {
				"field": "person_id",
				"link_type": "prevent delete",
				"table": "person"
			}
		},
		{
			"type": "varchar",
			"foreign_key": {
				"field": "company_id",
				"link_type": "prevent delete",
				"table": "company"
			},
			"length": 40,
			"nullable": true,
			"name": "subcontractor_id"
		},
		{
			"name": "event_time",
			"type": "datetime"
		},
		{
			"name": "subcontract",
			"type": "boolean"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "work_phase_type"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "work_phase_state"
		},
		{
			"name": "product_work_state",
			"type": "integer"
		},
		{
			"name": "work_phase_number",
			"type": "integer"
		},
		{
			"name": "machine_hours",
			"type": "double"
		},
		{
			"name": "work_hours",
			"type": "double"
		},
		{
			"name": "setup_hours",
			"type": "double"
		},
		{
			"name": "extra_hours",
			"type": "double"
		},
		{
			"name": "started_amount",
			"type": "double"
		},
		{
			"name": "produced_amount",
			"type": "double"
		},
		{
			"name": "failed_amount",
			"type": "double"
		},
		{
			"name": "remaining_amount",
			"type": "double"
		},
		{
			"name": "setup_hourly_salary",
			"type": "double"
		},
		{
			"name": "work_hourly_salary",
			"type": "double"
		},
		{
			"name": "setup_hourly_self_cost",
			"type": "double"
		},
		{
			"name": "work_hourly_self_cost",
			"type": "double"
		},
		{
			"name": "salary",
			"type": "double"
		},
		{
			"name": "cost_price",
			"type": "double"
		},
		{
			"name": "profit_multiplier",
			"type": "double"
		},
		{
			"name": "sales_price",
			"type": "double"
		},
		{
			"name": "description",
			"type": "text"
		},
		{
			"name": "info",
			"type": "text"
		},
		{
			"name": "json_data",
			"type": "jsonb"
		}
	],
	"constraint": {
		"save": {
			"allow": [{
				"field": "prwo_resource_id",
				"message": "Field '%s' may not be empty",
				"code": [
					[
						"prwo_resource_id",
						"<>",
						""
					]
				]
			}]
		}
	},
	"extra_field": [
		{
			"type": "date",
			"name": "json_data.act_end_date"
		},
		{
			"type": "double",
			"name": "json_data.advance"
		},
		{
			"type": "integer",
			"name": "json_data.critical_date_difference"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.customer_project"
		},
		{
			"type": "double",
			"name": "json_data.delay"
		},
		{
			"type": "integer",
			"name": "json_data.delivery_to_customer"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.employee_id"
		},
		{
			"type": "date",
			"name": "json_data.end_time"
		},
		{
			"type": "double",
			"name": "json_data.est_bonus_work_time__unit"
		},
		{
			"type": "double",
			"name": "json_data.est_contract_price__unit"
		},
		{
			"type": "double",
			"name": "json_data.est_machine_setup_cost__hour"
		},
		{
			"type": "double",
			"name": "json_data.est_machine_work_cost__hour"
		},
		{
			"type": "double",
			"name": "json_data.est_salary__hour"
		},
		{
			"type": "double",
			"name": "json_data.est_setup_salary__hour"
		},
		{
			"type": "double",
			"name": "json_data.setup_hours"
		},
		{
			"type": "double",
			"name": "json_data.est_work_time__unit"
		},
		{
			"type": "date",
			"name": "json_data.extra_end_time"
		},
		{
			"type": "integer",
			"name": "json_data.firm_id"
		},
		{
			"type": "integer",
			"name": "json_data.link_target"
		},
		{
			"type": "boolean",
			"name": "json_data.link_to_start"
		},
		{
			"type": "double",
			"name": "json_data.linking_hours"
		},
		{
			"type": "double",
			"name": "json_data.load_multiplier"
		},
		{
			"type": "integer",
			"name": "json_data.material_owner"
		},
		{
			"type": "double",
			"name": "json_data.measured_track_time"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.modifier_id"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.next_phase"
		},
		{
			"type": "date",
			"name": "json_data.critical_delayed_start_date"
		},
		{
			"type": "date",
			"name": "json_data.critical_end_time"
		},
		{
			"type": "date",
			"name": "json_data.critical_delayed_end_date"
		},
		{
			"type": "date",
			"name": "json_data.critical_extra_end_time"
		},
		{
			"type": "date",
			"name": "json_data.critical_start_time"
		},
		{
			"type": "double",
			"name": "json_data.planned_work_time"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.previous_phase"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.prod_lot__linked_phase"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.production_lot__work_ph"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.project_id"
		},
		{
			"type": "integer",
			"name": "json_data.reclamation_count"
		},
		{
			"type": "double",
			"name": "hours"
		},
		{
			"type": "date",
			"name": "json_data.start_time"
		},
		{
			"type": "boolean",
			"name": "json_data.subcontract"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.subtype"
		},
		{
			"type": "double",
			"name": "json_data.target_machine_time"
		},
		{
			"type": "double",
			"name": "json_data.target_time"
		},
		{
			"type": "double",
			"name": "json_data.track_time"
		},
		{
			"type": "integer",
			"name": "json_data.track_time_status"
		},
		{
			"type": "varchar",
			"length": 120,
			"name": "json_data.transfer_id"
		},
		{
			"type": "integer",
			"name": "json_data.transfer_state"
		},
		{
			"type": "double",
			"name": "json_data.urgency_index"
		},
		{
			"type": "double",
			"name": "json_data.work_time"
		},
		{
			"type": "double",
			"name": "json_data.contract_multiplier"
		},
		{
			"type": "double",
			"name": "json_data.contract_price__unit"
		},
		{
			"type": "boolean",
			"name": "json_data.contract_salary"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.cost_center"
		},
		{
			"type": "date",
			"name": "json_data.end_date"
		},
		{
			"type": "double",
			"name": "json_data.evening_work_hours"
		},
		{
			"type": "boolean",
			"name": "json_data.hourly_salary"
		},
		{
			"type": "double",
			"name": "json_data.kind"
		},
		{
			"type": "double",
			"name": "json_data.night_work_hours"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.parcel_code"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.program_id"
		},
		{
			"type": "double",
			"name": "json_data.salary_bonus"
		},
		{
			"type": "integer",
			"name": "json_data.work_shift"
		},
		{
			"type": "varchar",
			"length": 80,
			"name": "json_data.smelting_num"
		},
		{
			"type": "double",
			"name": "json_data.social_cost_multiplier"
		},
		{
			"type": "date",
			"name": "json_data.start_date"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.start_person_id"
		},
		{
			"type": "integer",
			"name": "json_data.start_work_shift"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.start_subtype"
		},
		{
			"type": "varchar",
			"length": 20,
			"name": "json_data.stock_event_id"
		},
		{
			"type": "varchar",
			"length": 40,
			"name": "json_data.supplier_id"
		},
		{
			"type": "double",
			"name": "json_data.unpaid_hours"
		},
		{
			"type": "varchar",
			"length": 24,
			"name": "json_data.user_id"
		},
		{
			"type": "varchar",
			"length": 60,
			"name": "json_data.work_number"
		},
		{
			"type": "integer",
			"name": "json_data.work_phase_actual_id"
		},
		{
			"type": "double",
			"name": "json_data.bonus_work_time__unit"
		},
		{
			"type": "double",
			"name": "json_data.contract_default_salary"
		},
		{
			"type": "varchar",
			"length": 4,
			"name": "json_data.cover__inside"
		},
		{
			"type": "integer",
			"name": "json_data.phase_number"
		},
		{
			"type": "double",
			"name": "json_data.pieces__unit"
		},
		{
			"type": "double",
			"name": "json_data.purchase_multiplier"
		},
		{
			"type": "double",
			"name": "json_data.rest_time__hour"
		},
		{
			"type": "integer",
			"name": "json_data.run_amount"
		},
		{
			"type": "double",
			"name": "json_data.setup_amount"
		},
		{
			"type": "double",
			"name": "json_data.special_extra_hours"
		},
		{
			"type": "double",
			"name": "json_data.speed_unit"
		},
		{
			"type": "double",
			"name": "json_data.subc_profit_multiplier"
		},
		{
			"type": "double",
			"name": "json_data.subcont_cost__unit"
		},
		{
			"type": "double",
			"name": "json_data.subcont_cost_total"
		},
		{
			"type": "double",
			"name": "json_data.subcont_purc_price__unit"
		},
		{
			"type": "double",
			"name": "json_data.subcont_sales_price__unit"
		},
		{
			"type": "double",
			"name": "json_data.subcont_sales_price_total"
		},
		{
			"type": "varchar",
			"length": 160,
			"name": "json_data.tag"
		},
		{
			"type": "double",
			"name": "json_data.target_extra_time"
		},
		{
			"type": "double",
			"name": "json_data.target_extra_time__unit"
		},
		{
			"type": "double",
			"name": "json_data.units_in_hour"
		},
		{
			"type": "varchar",
			"length": 60,
			"name": "json_data.work__position_num_id"
		},
		{
			"type": "double",
			"name": "json_data.work_cost_total"
		},
		{
			"type": "double",
			"name": "json_data.work_salary__unit"
		},
		{
			"type": "double",
			"name": "json_data.work_sales_price_total"
		},
		{
			"type": "double",
			"name": "json_data.work_time__lot"
		}
	],
	"calculated_field": [
		{
		"type": "double",
		"script": [
			[
				"prwo_work_hours",
				"=",
				[
					1,
					"/",
					"prwo_units_in_hour"
				]
			],
			[
				"prwo_C_KENTAT"
			]
		],
		"name": "prwo_units_in_hour",
		"code": [
			[
				"prwo_units_in_hour",
				"=",
				[
					1,
					"/",
					"prwo_work_hours"
				]
			]
		]
	}],
	"field_change": [{
		"name": "product_work_state",
		"old_name": [
			"record_state"
		]
	}]
}