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