CREATE OR REPLACE VIEW forecast_requests AS
	SELECT
		request.*,
		date_cancelled AS forecast_date_cancelled,
		(CASE WHEN TIME(date_issued) < 730 THEN
				DATE_SUB(date_issued, INTERVAL 1 DAY)
			ELSE
				date_issued
		END) as forecast_date_issued,
		job_type.include_issued,
		job_type.include_cancelled,
		(
			status.forecast AND job_category.forecast AND job_type.forecast
		) as forecast
	FROM
		vrequests request
	JOIN statuses status
		ON (
			status.id = request.status_id
		)
	JOIN job_categories job_category
		ON (
			job_category.id = request.job_category_id
		)
	JOIN job_types job_type
		ON (
			job_type.id = request.job_type_id
		)
	JOIN operating_areas operating_area
		ON operating_area.id = request.operating_area_id;