
import at.clockwork.security.domain.*
import at.clockwork.time.domain.*




class UpdateScriptService {

	def run(def connection, def dataSourceFields) {

		boolean error = true

		Date dateFrom = new Date(2008-1900, 0, 1)
		Date dateTo = new Date()

		for (date in dateFrom..dateTo) {
			if (date.getMonth() != (date+1).getMonth()) {
				def resultMap = at.clockwork.system.service.DataSourceService.execute(
					connection,
					dataSourceFields,
					[
						mySQLStatement:"insert into cw_time_time_type_data_total (version, person_id, date, time_time_type_id, total_value) select 0, person_id, date, time_time_type_id, sal from cw_time_time_type_data where date = '" + date.format("yyyy-MM-dd") + "'",
						msSQLStatement:"insert into cw_time_time_type_data_total (version, person_id, date, time_time_type_id, total_value) select 0, person_id, date, time_time_type_id, sal from cw_time_time_type_data where convert(varchar(10), date, 120) = '" + date.format("yyyy-MM-dd") + "'"
					]
				)
			}
		}

		error
	}
}
