Você está na página 1de 15

Public Sub tratanormal_unica()

Arquivo ativo: controle oficiais atual no USB e no c:

Jump:
'tudo
__________________________________________________________________________________________________________________________

'testes
Dim DATA01, DATA02, datak, datay As Date

DATA01 = Format(DateAdd("D", 5, CDate(dauxesc)), "MM/DD/YYYY")


DATA02 = Format(DateAdd("D", -2, CDate(dauxesc)), "MM/DD/YYYY")
'EXIT SUB
' MsgBox SQL
SQL = "select COUNT(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') "

' MsgBox SQL


Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

'-----------------------------------------------------------------------------------------------------------------------------

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check fds
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check vip
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& " data_FIM_AFAST >= '" & DateAdd("d", 2, Format(CDate(dauxesc), "MM/DD/YYYY")) & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else

'bloco com apenas teste nas datas de quem não tem o check_fds ou o check vip

'tudo - sem check vip


'com teste de vip na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
'tudo - sem check fds
'com teste de fim de semana na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& " oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_vip <=1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_vip <=1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
'tudo - sem nenhum check
'com teste de fim de semana e vip 24h na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_escala_ano <> " & cboAno.Text & " and oficial_escala_mes <> '" & cboMes.Text & "' and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '"
& DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else

'agora repete tudo sem mes e ano

'tudo
__________________________________________________________________________________________________________________________
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 & "')
"
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check fds
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02
& "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check vip
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else

'bloco com apenas teste nas datas de quem não tem o check_fds ou o check vip

'tudo - sem check vip


'com teste de vip na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
'tudo - sem check fds
'com teste de fim de semana na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_vip <=1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_check_vip <=1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
'tudo - sem nenhum check
'com teste de fim de semana e vip 24h na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '"
& DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else

'agora trata a possibilidade de combinar um vip/24horas com normal em algum momento na escala mensal
'tudo
__________________________________________________________________________________________________________________________
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 & "')
"
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check fds
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02 &
"') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing

If Cont <> 0 Then


SQL = "" 'ok
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
'ok
Else
'tudo - sem check vip
'com teste de fim de semana e teste de vip/24h
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" & DATA02
& "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select diario from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else

'bloco com apenas teste nas datas de quem não tem o check_fds ou o check vip

'tudo - sem check vip


'com teste de vip na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_fds = 0 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
'MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
'tudo - sem check fds
'sem check vip
'com teste de fim de semana na escala
'com teste vip e 24h na escala
SQL = "select count(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial WHERE " _
& "oficial_check_normal <= 1 and " _
& " oficial_cont_vip <= 1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_cont_N <= 1 and " _
& " oficial_id not in (select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select oficial_id from v_estatistica_oficial where normal > 1 and mes = '" & cboMes.Text & "') and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
' MsgBox oficial_aux
Rs3.Close
Set Rs3 = Nothing
Else
SQL = "select count(oficial_id) as soma from tab_oficial where " _
& " oficial_check_normal <=1 and " _
& " oficial_cont_vip <=1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') "
Set Rs3 = De.Cn.Execute(SQL)
Cont = 0
Cont = Rs3!soma
Rs3.Close
Set Rs3 = Nothing
If Cont <> 0 Then
SQL = "select min(oficial_ordem) as soma from tab_oficial where " _
& " oficial_check_normal <=1 and " _
& " oficial_cont_vip <=1 and " _
& " oficial_check_p = 0 and " _
& " oficial_check_f = 0 and" _
& " oficial_escala_id <> " & Cod & " and " _
& " oficial_grupo_id = " & grupo1 & " and " _
& " oficial_grupo_id <> 9 and " _
& " oficial_id not in (select vip from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in (select diario from tab_escala where escala_id = " & Cod & ") and " _
& " oficial_id not in(select fds_vip from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id not in(select fds_24h from tab_escala where mes = '" & cboMes & "' and ano = " & cboAno.Text & ") and " _
& " oficial_id NOT in(select oficial_id from tab_afastamentos where data_inicial_afast <= '" & DATA01 & "' AND data_FIM_AFAST >= '" &
DATA02 & "') " _
& terminasql
Set Rs3 = De.Cn.Execute(SQL)
oficial_aux = 0
oficial_aux = Rs3!soma
Rs3.Close
Set Rs = Nothing
Else
Call zeratab
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

Você também pode gostar