import at.clockwork.terminal.domain.*
import at.clockwork.system.domain.*

import grails.util.Holders

class UpdateScriptService {


	def run(def connection, def dataSourceFields) {

        Terminal.findAllWhere(terminalType : TerminalType.findWhere( cwID : TerminalType.DATAFOX_TIME_ONLINE, deleted:false ) ).each { terminal ->

            if (!TerminalDatafox.get(terminal.id)) {

                def resultMap = at.clockwork.system.service.DataSourceService.execute(
                    connection,
                    dataSourceFields,
                    [
                        mySQLStatement:"""insert into cw_terminal_datafox (
                                        id, firmware_level, transfer_persons, person_list_name, transfer_projects, project_list_name, transfer_orders, order_list_name, transfer_order_items, order_item_list_name, transfer_cost_units, cost_unit_list_name, transfer_machines, machine_list_name, transfer_workplaces, workplace_list_name, transfer_workprocesses, workprocess_list_name, transfer_identifications, identification_list_name, check_authorisation,
                                        transfer_absences, absence_list_name, action1, anti_pass_back
                                        ) values (
                                        ${terminal.id}, 0, false, "", false, "", false, "", false, "", false, "", false, "", false, "", false, "", false, "", false,
                                        false, "", true, false
                                        )""",
                        msSQLStatement:"""insert into cw_terminal_datafox (
                                       id, firmware_level, transfer_persons, person_list_name, transfer_projects, project_list_name, transfer_orders, order_list_name, transfer_order_items, order_item_list_name, transfer_cost_units, cost_unit_list_name, transfer_machines, machine_list_name, transfer_workplaces, workplace_list_name, transfer_workprocesses, workprocess_list_name, transfer_identifications, identification_list_name, check_authorisation,
                                       transfer_absences, absence_list_name, action1, anti_pass_back
                                       ) values (
                                       ${terminal.id}, 0, 0, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0,
                                       0, "", 1, 0
                                       )"""
                    ]
                )

    		}

        }

		true
	}
}