import com.dvelop.d3.server.core.D3Interface;
import com.dvelop.d3.server.Document;
import com.dvelop.d3.server.User;
import com.dvelop.d3.server.DocumentType;
import com.dvelop.d3.server.ValueSet;
import com.dvelop.d3.server.RepositoryField;



public class ValueSetsCombined
{

	@ValueSet( entrypoint = "PERS_Dokumenttyp" )
	def PERS_Dokumenttyp( D3Interface d3, RepositoryField reposField, User user, DocumentType docType, int rowNo, int validate, Document doc )
	{
		def where = "";
		if ( doc.field[ 15 ] )
		{
			where = " and dok_dat_feld_20 = '" + doc.field[ 15 ] + "' "
		}
		
		def sqlQuery = "select distinct dok_dat_feld_21 DDF from firmen_spezifisch where kue_dokuart = 'AADM' " + where + " order by dok_dat_feld_21 ";
		
		def resultRows = d3.sql.executeAndGet( (String) sqlQuery );
		
		if ( resultRows.size() > 0 )
		{
			reposField.provideValuesForValueSet( resultRows.collect{ it.DDF } );
		}
	}
	
	@ValueSet( entrypoint = "PERS_Register" )
	def PERS_Register( D3Interface d3, RepositoryField reposField, User user, DocumentType docType, int rowNo, int validate, Document doc )
	{
		def sqlQuery = "select distinct dok_dat_feld_20 DDF from firmen_spezifisch where kue_dokuart = 'AADM'" + " order by dok_dat_feld_20 ";
		
		def resultRows = d3.sql.executeAndGet( (String) sqlQuery );
		
		if ( resultRows.size() > 0 )
		{
			reposField.provideValuesForValueSet( resultRows.collect{ it.DDF } );
		}
	}
	
	@ValueSet( entrypoint = "PERS_PersonalNr" )
	def PERS_PersonalNr( D3Interface d3, RepositoryField reposField, User user, DocumentType docType, int rowNo, int validate, Document doc )
	{
		def sqlQuery = "select dok_dat_feld_1 || ' | ' || dok_dat_feld_3 || ' | ' || dok_dat_feld_2 mitarbeiter from firmen_spezifisch where kue_dokuart = 'APERS' order by mitarbeiter ";
		
		def resultRows = d3.sql.executeAndGet( (String) sqlQuery );
		
		if ( resultRows.size() > 0 )
		{
			reposField.provideValuesForValueSet( resultRows.collect{ it.mitarbeiter } );
		}
	}
}