{
	"name": "form/nc/report/lead-time/filter_map_reduce/lead-time-map.json",
	"definition": {
		"order_days": {
			"table": "ordr",
			"map": [
				[
					"if",
					["pro_print_date", ">", "1970-01-01"],
					[["order_days", "=", ["dayDifference", ["ord.order_date", "pro_print_date"]]]],
					"else",
					[["order_days", "=", ["dayDifference", ["ord.order_date", "work_start_date"]]]]
				]
			]
		},
		"work_start_days": {
			"table": "ordr",
			"map": [
				[
					"if",
					["pro_print_date", ">", "1970-01-01"],
					[["work_start_days", "=", ["dayDifference", ["pro_print_date", "work_start_date"]]]],
					"else",
					[["work_start_days", "=", 0]]
				]
			]
		},
		"production_days": {
			"table": "ordr",
			"map": [["production_days", "=", ["dayDifference", ["work_start_date", "work_end_date"]]]]
		},
		"delivery_days": {
			"table": "ordr",
			"map": [["delivery_days", "=", ["dayDifference", ["work_end_date", "ordr.actual_delivery_date"]]]]
		},
		"productive_time": {
			"table": "ordr",
			"map": [
				[
					"if",
					["pro.produced_amount", "<>", 0],
					[["productive_time", "=", ["work_time", "/", "pro.produced_amount"]]],
					"else",
					[["productive_time", "=", 0]]
				]
			]
		},
		"order_lead_time": {
			"info2": ["order_lead_time", "=", ["percent", ["actual_hour", "planned_hour"]]],
			"table": "ordr",
			"map": [["order_lead_time", "=", ["dayDifference", ["ord.order_date", "ordr.actual_delivery_date"]]]]
		},
		"production_lead_time": {
			"table": "ordr",
			"map": [
				[
					"if",
					["pro_print_date", ">", "1970-01-01"],
					[["production_lead_time", "=", ["dayDifference", ["pro_print_date", "work_end_date"]]]],
					"else",
					[["production_lead_time", "=", ["dayDifference", ["work_start_date", "work_end_date"]]]]
				]
			]
		},
		"unproductive_time": {
			"table": "ordr",
			"map": [
				[
					"if",
					["productive_time", "<>", 0],
					[["unproductive_time", "=", ["production_lead_time", "-", ["productive_time", "/", 24]]]],
					"else",
					[["unproductive_time", "=", 0]]
				]
			]
		},
		"productive_percent": {
			"table": "ordr",
			"map": [
				[
					"if",
					["production_days", "<>", 0],
					[["productive_percent", "=", ["productive_time", "/", ["production_days", "*", 24]]]],
					"else",
					[["productive_percent", "=", 0]]
				]
			]
		},

		"order_row": {
			"filter": { "name": "form/local/lead_time/lead_time_filter.json", "definition": "order_row_production_order" },
			"table": "pro",
			"sum": [["work_time", "=", "work_time"]],
			"min": [["work_start_date"]],
			"max": [["work_end_date"]],
			"map-": [
				["if", ["work_start_date", ">", "work_start_date"], [["work_start_date", "=", "work_start_date"]]],
				["if", ["work_end_date", "<", "work_end_date"], [["work_end_date", "=", "work_end_date"]]]
			]
		}
	}
}
