




class UpdateScriptService {

	def run(def connection, def dataSourceFields) {

		def resultMap = at.clockwork.system.service.DataSourceService.execute(
			connection,
			dataSourceFields,
			[
				mySQLStatement:"update cw_time_time_type set reduce_total = true where reduce_total is null",
				msSQLStatement:"update cw_time_time_type set reduce_total = 0 where reduce_total is null"
			]
		)

		resultMap = at.clockwork.system.service.DataSourceService.execute(
			connection,
			dataSourceFields,
			[
				mySQLStatement:"update cw_time_time_type set reduce_total = true where number = '40'",
				msSQLStatement:"update cw_time_time_type set reduce_total = 1 where number = '40'"
			]
		)

		long rowId = 0
		def row = connection.firstRow("select id from cw_time_time_type where number = '40'")
		if (row)
			rowId = row["id"]

		if (rowId > 0) {
			resultMap = at.clockwork.system.service.DataSourceService.execute(
				connection,
				dataSourceFields,
				[
					mySQLStatement:"update cw_time_time_type_data set day_value = day_value*(-1),  period_value = period_value*(-1),  changed_period_value = changed_period_value*(-1),  changed_total_value = changed_total_value*(-1) where time_time_type_id = " + rowId,
					msSQLStatement:"update cw_time_time_type_data set day_value = day_value*(-1),  period_value = period_value*(-1),  changed_period_value = changed_period_value*(-1),  changed_total_value = changed_total_value*(-1) where time_time_type_id = " + rowId
				]
			)
		}

		true
	}
}
