{
	"name": "query/manager/product/product_work/actual/productivity_report/old/time_period_after_old.json",
	"table": [
		{
			"record_type": ["actual"],
			"table": "product_work"
		}
	],
	"database": "4d",
	"parameter": {
		"end_date": "",
		"end_date2": "",
		"load_group": [
				
			],
		"production_lot": [
				
			],
		"show_sql": false,
		"subqueryX": "SELECT record_id FROM work_phase_actual WHERE CONCAT(production_lot, CONCAT('#', work_phase_est_id)) IN (SELECT CONCAT(production_lot, CONCAT('#', work_phase_est_id)) FROM work_phase_actual WHERE date_ BETWEEN '{{start_date2}}' AND '{{end_date2}}' AND work_load_group_id IN ({{load_group}}))",
		"subqueryXX": "SELECT CONCAT(production_lot, CONCAT('#', work_phase_est_id)) AS id, SUM(work_time__amount) FROM work_phase_actual WHERE date_ >= '{{end_date}}' AND (date_ <> '{{end_date}}' OR (end_time >= '12:00:00' AND shift_number = 1)) AND (date_ <> '{{end_date2}}' OR end_time >= '12:00:00' OR shift_number < 3) AND work_load_group_id IN ({{load_group}}) GROUP BY id",
		"track_time_type": "OA"
	},
	"field": [
		"prwo.resource_id",
		"prwo.production_lot",
		"prwo.work_phase_number",
		"prwo.work_hours"
	],
	"aggregate": {
		"sum": ["prwo.work_hours"]
	},
	"orderXX": ["prwo.json_data.end_date", ">"],
	"query": [
		["prwo.json_data.end_date", ">=", "end_date"],
		"and",
		["prwo.work_phase_type", "<>", "track_time_type"],
		"and",
		["take_shift_in_end_date"],
		"and",
		["remove_next_day_shift"],
		"and",
		["prwo.resource_id", "in", "load_group"],
		"and",
		["prwo.production_lot", "in", "production_lot"]
	],
	"set": {
		"remove_next_day_shift": [
				["prwo.json_data.end_date", "<>", "end_date2"],
				"or",
				["prwo.json_data.end_time", ">=", "12:00:00"],
				"or",
				["prwo.json_data.work_shift", "<", 3]
			],
		"shift_in_end_date": [
				["prwo.json_data.end_time", ">=", "12:00:00"],
				"and",
				["prwo.json_data.work_shift", "=", 1]
			],
		"take_shift_in_end_date": [
				["prwo.json_data.end_date", "<>", "end_date"],
				"or",
				"shift_in_end_date"
			]
	}
}