Jump to content

How to calculate business days?


Recommended Posts

I need to know how many days business have in a given period eg 04/27/2014 to 10/05/2014, there is filtering function to do this?

Link to comment
Share on other sites

There is no ready-to-use function I know of

But you could use functions _DateToDayOfWeek and _DateAdd in a loop to calculate the number of work days.

How would you handle holidays?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Holidays are really a problem, I have to create an .ini file Containing all holidays.

Edited by Belini
Link to comment
Share on other sites

Just a quick sample without taking care of public holidays, etc. and bussiness days from Monday to Friday:

#include <Date.au3>
$sStartDate = "2014/04/27"
$sEndDate = "2014/05/10"

$iBussinessDays = _BussinessDays($sStartDate, $sEndDate)
ConsoleWrite("There are " & $iBussinessDays & " bussiness days between " & $sStartDate & " and " & $sEndDate & @CRLF)

Func _BussinessDays($sStartDate, $sEndDate)
    $iCounter = 0
    $iDifferenceInDays = _DateDiff('D', $sStartDate, $sEndDate)
    For $i = 0 To $iDifferenceInDays
        $sNextDate = _DateAdd('D', $i, $sStartDate)
        $aSplitDate = StringSplit($sNextDate, "/")
        $sDayOfWeek = _DateToDayOfWeekISO($aSplitDate[1], $aSplitDate[2], $aSplitDate[3])
        If $sDayOfWeek >= 1 And $sDayOfWeek <= 5 Then
            $iCounter += 1
        EndIf
    Next
    Return $iCounter
EndFunc   ;==>_BussinessDays

Cheers,

sahsanu

Link to comment
Share on other sites

Thanks to all who responded, @ sahsanu I'll put the holiday in your example and will stay as I want.

Link to comment
Share on other sites

With these functions date made ​​a script to check whether the couriers are delivering the order on time.
 

 
Source:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icone.ico
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=Função: Verificar se os correios cumpriram o prazo de entrega.
#AutoIt3Wrapper_Res_Description=Autoit3 3.3.9.4
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Feito por Belini em 16/05/2014
;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


; ============================================================================
; Autoit3 3.3.9.4
; Autor: Belini
; Data: 16/05/2014
; Objetivo: Verificar se os correios cumpriram o prazo de entrega.
; ============================================================================


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>


Global $extrai_inicio, $extrai_final, $confere, $data_fixa[9], $Data_movel[4], $lab_fixa[9], $lab_movel[4]
Global $inp_dest, $inp_rast, $Inp_postagem, $Inp_previsao, $inp_entrega, $But_incluir, $gui_principal
Global $But_edit_mov, $But_fer_moveis, $inp_alt_entrega, $But_alt_incluir, $Inp_alt_previsao
Global $gui_alt_dados, $inp_alt_dest, $But_alterar, $inp_alt_rast, $Inp_alt_postagem, $nMsg
Global $sem_dados = 0, $But_alt_dados, $But_excl_linha, $List_rastreio, $gui_feriados
Global $le_inp1, $le_inp2, $le_inp3, $le_inp4, $le_inp5


; ====================================================================================================================== Gui principal
$gui_principal = GUICreate("Acompanhamento de entrega dos correios.", 896, 746, -1, -1)
GUICtrlCreateGroup("Acompanhamento de entrega dos correios ", 8, 12, 881, 100)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlCreateLabel("Destinatário:", 16, 44, 73, 19)
GUICtrlCreateLabel("Nº rastreio:", 264, 44, 52, 19)
GUICtrlCreateLabel("Dia postagem:", 418, 44, 70, 19)
GUICtrlCreateLabel("Previsão dias:", 569, 44, 80, 19)
GUICtrlCreateLabel("Dia entrega:", 690, 44, 64, 19)
$inp_dest = GUICtrlCreateInput("", 80, 41, 172, 23)
$inp_rast = GUICtrlCreateInput("", 320, 41, 86, 23)
$Inp_postagem = GUICtrlCreateInput(@MDAY & "/" & @MON & "/" & @YEAR, 490, 41, 68, 23, $ES_CENTER)
$Inp_previsao = GUICtrlCreateInput("", 640, 41, 39, 23, BitOR($ES_AUTOHSCROLL, $ES_CENTER, $ES_NUMBER))
$inp_entrega = GUICtrlCreateInput("", 752, 41, 68, 23, $ES_CENTER)
$But_incluir = GUICtrlCreateButton("Incluir", 828, 38, 51, 25)
$But_alterar = GUICtrlCreateButton("Alterar dados da linha selecionada", 20, 74, 224, 25)
$But_excl_linha = GUICtrlCreateButton("Excluir dados da linha selecionada", 339, 74, 224, 25)
$But_fer_moveis = GUICtrlCreateButton("Editar data dos feriados móveis", 655, 74, 224, 25)
$List_rastreio = GUICtrlCreateListView("                           Nome destinatário| Nº rastreio|Data que foi postado|Previsão|Data " & _
"que foi entregue|Dias úteis| Cumpriu prazo", _
8, 122, 879, 617, BitOR($LVS_SHOWSELALWAYS, $ES_CENTER), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
_GUICtrlListView_SetColumnWidth($List_rastreio, 0, 270)
_GUICtrlListView_SetColumnWidth($List_rastreio, 1, 80)
_GUICtrlListView_SetColumnWidth($List_rastreio, 2, 130)
_GUICtrlListView_SetColumnWidth($List_rastreio, 3, 65)
_GUICtrlListView_SetColumnWidth($List_rastreio, 4, 136)
_GUICtrlListView_SetColumnWidth($List_rastreio, 5, 72)
_GUICtrlListView_SetColumnWidth($List_rastreio, 6, 100)
GUISetState(@SW_SHOW, $gui_principal)
; ====================================================================================================================== Gui principal


; ======================================================================================================================= Gui Feriados
$gui_feriados = GUICreate("                 Editar data dos feriados:", 238, 411, -1, -1, $GUI_SS_DEFAULT_GUI - $WS_SYSMENU)
GUICtrlCreateGroup("Feriados móveis ", 8, 8, 223, 129)
GUICtrlCreateGroup("Feriados Fixos ", 8, 145, 223, 217)
$Data_movel[1] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "1", "")
$Data_movel[2] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "2", "")
$Data_movel[3] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "3", "")
$extrai_inicio = StringMid($Data_movel[1], 1, StringInStr($Data_movel[1], "/", 2, 1) - 1)
If StringLen($extrai_inicio) = "" Then $extrai_inicio = @YEAR
$data_fixa[1] = $extrai_inicio & "/01/01"
$data_fixa[2] = $extrai_inicio & "/04/21"
$data_fixa[3] = $extrai_inicio & "/05/01"
$data_fixa[4] = $extrai_inicio & "/09/07"
$data_fixa[5] = $extrai_inicio & "/10/12"
$data_fixa[6] = $extrai_inicio & "/11/02"
$data_fixa[7] = $extrai_inicio & "/11/15"
$data_fixa[8] = $extrai_inicio & "/12/25"
$data_fixa[8] = $extrai_inicio & "/01/01"
$lab_fixa[1] = GUICtrlCreateLabel("01/01/" & $extrai_inicio & " - Confraternização Universal", 17, 171, 200, 18)
$lab_fixa[2] = GUICtrlCreateLabel("21/04/" & $extrai_inicio & " - Tiradentes", 17, 194, 128, 18)
$lab_fixa[3] = GUICtrlCreateLabel("01/05/" & $extrai_inicio & " - Dia do Trabalhador", 17, 217, 170, 18)
$lab_fixa[4] = GUICtrlCreateLabel("09/07/" & $extrai_inicio & " - Independência", 17, 240, 149, 18)
$lab_fixa[5] = GUICtrlCreateLabel("12/10/" & $extrai_inicio & " - Nossa Senhora Aparecida", 17, 263, 209, 18)
$lab_fixa[6] = GUICtrlCreateLabel("02/11/" & $extrai_inicio & " - Finados", 17, 286, 111, 18)
$lab_fixa[7] = GUICtrlCreateLabel("15/11/" & $extrai_inicio & " - Proclamação da República", 17, 309, 210, 18)
$lab_fixa[8] = GUICtrlCreateLabel("25/12/" & $extrai_inicio & " - Natal", 17, 332, 94, 18)
GUICtrlCreateLabel("Carnaval", 112, 32, 61, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlCreateLabel("Sexta feira santa", 112, 64, 112, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlCreateLabel("Corpus Christi", 112, 96, 92, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")


$confere = StringMid($Data_movel[1], 1, StringInStr($Data_movel[1], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
$confere = inverte_data($Data_movel[1])
Else
$confere = $Data_movel[1]
EndIf
$lab_movel[1] = GUICtrlCreateInput($confere, 16, 32, 89, 22, $ES_CENTER)


$confere = StringMid($Data_movel[2], 1, StringInStr($Data_movel[2], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
$confere = inverte_data($Data_movel[2])
Else
$confere = $Data_movel[2]
EndIf
$lab_movel[2] = GUICtrlCreateInput($confere, 16, 64, 89, 22, $ES_CENTER)


$confere = StringMid($Data_movel[3], 1, StringInStr($Data_movel[3], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
$confere = inverte_data($Data_movel[3])
Else
$confere = $Data_movel[3]
EndIf
$lab_movel[3] = GUICtrlCreateInput($confere, 16, 96, 89, 22, $ES_CENTER)


GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
$But_edit_mov = GUICtrlCreateButton("Editar data dos feriados móveis", 8, 376, 222, 25)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUISetState(@SW_HIDE, $gui_feriados)
; ======================================================================================================================= Gui Feriados


; =================================================================================================================== Gui Altera dados
$gui_alt_dados = GUICreate("Alteração de dados.", 897, 93, -1, 280, $WS_POPUP, $WS_EX_DLGMODALFRAME)
GUICtrlCreateGroup("Alteraração de dados ", 8, 5, 881, 76)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlCreateLabel("Destinatário:", 16, 40, 73, 19)
GUICtrlCreateLabel("Nº rastreio:", 264, 40, 52, 19)
GUICtrlCreateLabel("Dia postagem:", 418, 40, 70, 19)
GUICtrlCreateLabel("Previsão dias:", 569, 40, 80, 19)
GUICtrlCreateLabel("Dia entrega:", 690, 40, 64, 19)


$le_inp1 = GUICtrlRead($inp_dest)
$le_inp2 = GUICtrlRead($inp_rast)
$le_inp3 = GUICtrlRead($Inp_postagem)
$le_inp4 = GUICtrlRead($Inp_previsao)
$le_inp5 = GUICtrlRead($inp_entrega)


$inp_alt_dest = GUICtrlCreateInput($le_inp1, 80, 37, 172, 23)
$inp_alt_rast = GUICtrlCreateInput($le_inp2, 320, 37, 86, 23)
$Inp_alt_postagem = GUICtrlCreateInput($le_inp3, 490, 37, 68, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
$Inp_alt_previsao = GUICtrlCreateInput($le_inp4, 640, 37, 39, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
$inp_alt_entrega = GUICtrlCreateInput($le_inp5, 752, 37, 68, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
$But_alt_dados = GUICtrlCreateButton("Alterar", 828, 34, 51, 25)
GUISetState(@SW_HIDE, $gui_alt_dados)
; =================================================================================================================== Gui Altera dados


atualiza_dados()


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $But_fer_moveis
GUISetState(@SW_HIDE, $gui_principal)
GUISetState(@SW_SHOW, $gui_feriados)
Case $But_alterar
altera_dados()
Case $But_incluir
inclui_dados()
Case $But_edit_mov
edit_feriados()
Case $But_excl_linha
exclui_linha()
Case $But_alt_dados
inclui_dados(1)
atualiza_dados()
EndSwitch
WEnd


Func atualiza_dados()
Local $lista, $i
Local $aArray = IniReadSection(@ScriptDir & "\Dados.ini", "DADOS")
Local $conta = UBound($aArray) - 1
If $conta > 0 Then
For $i = 1 To $conta
$lista = $aArray[$i][0] & $aArray[$i][1]
GUICtrlCreateListViewItem($lista, $List_rastreio)
Next
Else
$sem_dados = 1
EndIf
EndFunc   ;==>atualiza_dados


Func altera_dados()
GUISetState(@SW_HIDE, $gui_principal)
GUISetState(@SW_SHOW, $gui_alt_dados)
Local $extrai_inicio, $item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
Local $inf_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 0)
Local $inf_rast = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 1)
Local $inf_post = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 2)
Local $inf_prev = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 3)
Local $inf_entreg = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 4)


$extrai_inicio = StringMid($inf_post, 1, StringInStr($inf_post, "/", 2, 1) - 1)
If StringLen($extrai_inicio) > 2 Then $inf_post = inverte_data($inf_post)


$extrai_inicio = StringMid($inf_entreg, 1, StringInStr($inf_entreg, "/", 2, 1) - 1)
If StringLen($extrai_inicio) > 2 Then $inf_entreg = inverte_data($inf_entreg)


GUICtrlSetData($inp_alt_dest, $inf_dest)
GUICtrlSetData($inp_alt_rast, $inf_rast)
GUICtrlSetData($Inp_alt_postagem, $inf_post)
GUICtrlSetData($Inp_alt_previsao, $inf_prev)
GUICtrlSetData($inp_alt_entrega, $inf_entreg)
EndFunc   ;==>altera_dados


Func exclui_linha()
Local $item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
Local $nome_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel))
IniDelete(@ScriptDir & "\Dados.ini", "DADOS", $nome_dest)
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($List_rastreio), $item_sel)
EndFunc   ;==>exclui_linha


Func edit_feriados()
Local $ano, $extrai_ano
GUISetState(@SW_SHOW, $gui_feriados)


Local $le_fer_1 = GUICtrlRead($lab_movel[1])
$extrai_final = StringTrimLeft($le_fer_1, StringInStr($le_fer_1, "/", 2, -1))
If StringLen($extrai_final) > 2 Then $le_fer_1 = inverte_data($le_fer_1)
If _DateIsValid($le_fer_1) Then
IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "1", $le_fer_1)
Else
MsgBox(4096, "Data inválida", "A data do carnaval não é válida", 3)
GUICtrlSetData($lab_movel[1], @MDAY & "/" & @MON & "/" & @YEAR)
WinActivate("Editar data dos feriados:")
GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
EndIf


Local $le_fer_2 = GUICtrlRead($lab_movel[2])
$extrai_final = StringTrimLeft($le_fer_2, StringInStr($le_fer_2, "/", 2, -1))
If StringLen($extrai_final) > 2 Then $le_fer_2 = inverte_data($le_fer_2)
If _DateIsValid($le_fer_2) Then
IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "2", $le_fer_2)
Else
MsgBox(4096, "Data inválida", "A data sexta feira santa não é válida", 3)
GUICtrlSetData($lab_movel[2], @MDAY & "/" & @MON & "/" & @YEAR)
WinActivate("Editar data dos feriados:")
GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
EndIf


Local $le_fer_3 = GUICtrlRead($lab_movel[3])
$extrai_final = StringTrimLeft($le_fer_3, StringInStr($le_fer_3, "/", 2, -1))
If StringLen($extrai_final) > 2 Then $le_fer_3 = inverte_data($le_fer_3)
If _DateIsValid($le_fer_3) Then
IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "3", $le_fer_3)
Else
MsgBox(4096, "Data inválida", "A data de corpus christi não é válida", 3)
GUICtrlSetData($lab_movel[3], @MDAY & "/" & @MON & "/" & @YEAR)
WinActivate("Editar data dos feriados:")
GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
EndIf


$extrai_ano = StringTrimLeft($le_fer_1, StringInStr($le_fer_1, "/", 2, -1))
If StringLen($extrai_ano) > 2 Then
$ano = $extrai_ano
Else
$extrai_ano = StringMid($le_fer_1, 1, StringInStr($le_fer_1, "/", 2, 1) - 1)
If StringLen($extrai_ano) > 2 Then
$ano = $extrai_ano
Else
$ano = @YEAR
EndIf
EndIf


GUICtrlSetData($lab_fixa[1], "01/01/" & $ano & " - Confraternização Universal")
GUICtrlSetData($lab_fixa[2], "21/04/" & $ano & " - Tiradentes")
GUICtrlSetData($lab_fixa[3], "01/05/" & $ano & " - Dia do Trabalhador")
GUICtrlSetData($lab_fixa[4], "09/07/" & $ano & " - Independência")
GUICtrlSetData($lab_fixa[5], "12/10/" & $ano & " - Nossa Senhora Aparecida")
GUICtrlSetData($lab_fixa[6], "02/11/" & $ano & " - Finados")
GUICtrlSetData($lab_fixa[7], "15/11/" & $ano & " - Proclamação da República")
GUICtrlSetData($lab_fixa[8], "25/12/" & $ano & " - Natal")
If _DateIsValid($le_fer_1) And _DateIsValid($le_fer_2) And _DateIsValid($le_fer_3) Then
GUISetState(@SW_HIDE, $gui_feriados)
GUISetState(@SW_SHOW, $gui_principal)
EndIf
EndFunc   ;==>edit_feriados


Func inclui_dados($opt = 0)
Local $item_sel, $inf_dest, $prazo, $extrai_inicio, $extrai_final
Local $1, $2, $3, $4, $5, $6, $7, $dados, $data_ini, $data_fim


If $opt = 1 Then
_GUICtrlListView_DeleteAllItems($List_rastreio)
$1 = GUICtrlRead($inp_alt_dest)
$2 = GUICtrlRead($inp_alt_rast)
$3 = GUICtrlRead($Inp_alt_postagem)
$4 = GUICtrlRead($Inp_alt_previsao)
$5 = GUICtrlRead($inp_alt_entrega)
Else
$1 = GUICtrlRead($inp_dest)
$2 = GUICtrlRead($inp_rast)
$3 = GUICtrlRead($Inp_postagem)
$4 = GUICtrlRead($Inp_previsao)
$5 = GUICtrlRead($inp_entrega)
EndIf


$extrai_final = StringTrimLeft($3, StringInStr($3, "/", 2, -1))
If StringLen($extrai_final) > 2 Then
$data_ini = inverte_data($3)
Else
$data_ini = $3
EndIf


$extrai_final = StringTrimLeft($5, StringInStr($5, "/", 2, -1))
If StringLen($extrai_final) > 2 Then
$data_fim = inverte_data($5)
Else
$data_fim = $5
EndIf


If _DateIsValid($data_ini) = 1 And _DateIsValid($data_fim) = 1 Then
$6 = dias_uteis($data_ini, $data_fim)
Else
If _DateIsValid($data_fim) = 0 Then $6 = "-"
If _DateIsValid($data_ini) = 0 Then
GUICtrlSetData($Inp_alt_postagem, @MDAY & "/" & @MON & "/" & @YEAR)
GUICtrlSetData($Inp_postagem, @MDAY & "/" & @MON & "/" & @YEAR)
MsgBox(4096, "ERRO!", "A data de postagem não é válida, digite novamente!", 3)
EndIf


If _DateIsValid($5) = 0 Then $5 = "-"
EndIf


If $4 <> "" And $6 <> "" Then
$7 = $4 - $6
Else
If $6 = "" Then $6 = "-"
EndIf


If $7 >= 0 And $7 <> "" and $6 <> "-" Then
$prazo = "sim"
Else
If $7 = "" or $6 = "-" Then
$prazo = "-"
Else
$prazo = "Não"
EndIf
EndIf


If $1 <> "" And $2 <> "" And $3 <> "" And $4 <> "" Then
If $opt = 1 And _DateIsValid($data_ini) = 1 Then
$item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
$inf_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 0)
IniDelete(@ScriptDir & "\Dados.ini", "DADOS", $inf_dest)
GUISetState(@SW_SHOW, $gui_principal)
GUISetState(@SW_HIDE, $gui_alt_dados)
EndIf


$extrai_inicio = StringMid($3, 1, StringInStr($3, "/", 2, 1) - 1)
If StringLen($extrai_inicio) > 2 Then $3 = inverte_data($3)


$extrai_inicio = StringMid($5, 1, StringInStr($5, "/", 2, 1) - 1)
If StringLen($extrai_inicio) > 2 Then $5 = inverte_data($5)


$dados = $1 & "|" & $2 & "|" & $3 & "|" & $4 & "|" & $5 & "|" & $6 & "|" & $prazo
If $opt = 0 Then GUICtrlCreateListViewItem($dados, $List_rastreio)
GUICtrlSetData($inp_dest, "")
GUICtrlSetData($inp_rast, "")
GUICtrlSetData($Inp_previsao, "")
IniWrite(@ScriptDir & "\Dados.ini", "DADOS", $1, "|" & $2 & "|" & $3 & "|" & $4 & "|" & $5 & "|" & $6 & "|" & $prazo)
Else
If $1 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher o nome do destinatário para continuar!", 3)
If $2 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher o número do rastreio para continuar!", 3)
If $3 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher a data da postagem para continuar!", 3)
If $4 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher a previsão de entrega dos correios continuar!", 3)
EndIf
EndFunc   ;==>inclui_dados


Func inverte_data($data)
Local $corta_inicio = StringTrimLeft($data, StringInStr($data, "/", 2, 1) - 1)
Local $extrai_meio = StringMid($corta_inicio, 1, StringInStr($corta_inicio, "/", 2, -1))
Local $extrai_inicio = StringMid($data, 1, StringInStr($data, "/", 2, 1) - 1)
Local $extrai_final = StringTrimLeft($data, StringInStr($data, "/", 2, -1))
Local $data_invertida = $extrai_final & $extrai_meio & $extrai_inicio
Return $data_invertida
EndFunc   ;==>inverte_data


Func dias_uteis($data_ini, $data_fim)
Local $conta = 0, $i, $i2, $i3, $feriado, $nova_data, $separa_data
Local $dia_semana, $diferenca = _DateDiff('D', $data_ini, $data_fim)
For $i = 0 To $diferenca
$nova_data = _DateAdd('D', $i, $data_ini)
$feriado = 0
For $i2 = 1 To 8
If $data_fixa[$i2] = $nova_data Then $feriado = 1
Next
If $feriado = 0 Then
For $i3 = 1 To 3
If $Data_movel[$i3] = $nova_data Then $feriado = 1
Next
EndIf
$separa_data = StringSplit($nova_data, "/")
$dia_semana = _DateToDayOfWeekISO($separa_data[1], $separa_data[2], $separa_data[3])
If $dia_semana >= 1 And $dia_semana <= 5 And $feriado = 0 Then
$conta += 1
EndIf
Next
Return $conta
EndFunc   ;==>dias_uteis

NOTE: Sorry I have not had time to translate the code into English.

Edited by Belini
Link to comment
Share on other sites

  • 3 weeks later...

My coding might be a bit sloppy, but here is my attempt at finding holidays, both set days and floating days.

#include <Date.au3>

#cs

SHDay are Set Holidays.  The month and days are the same each year.
Set Days:
new years day; 01,01
july 4th; 07,04
christmas day; 12,25


VHDay are Variable Holidays. The month and days may vary on:

Variable Days:

MLKJr Day; 1,3,2 (3rd Monday in January)
President's Day; 2,3,2 (3rd Monday in February)
Labor Day; 9,1,2 (1st Monday in September)
Thanksgiving Day; 11,4,5 (4th Thursday in November)

Memorial Day Exception:
Memorial Day Last Monday in May (see May calculation)

Easter (see Easter Mess)
Good Friday (friday before easter)


Non-Bank Holidays:
Father's Day; 6,3,1 (3rd Sunday June)
Mother's Day; 5,2,1 (2nd Sunday in May)

Special Thanks To:
http://www.cpearson.com/Excel/holidays.htm
http://www.cpearson.com/Excel/Easter.aspx
#ce



Local $y, $m, $n, $dow, $datecheck, $test, $downew, $holiday = 0, $testday, $ec, $en, $ek, $ei, $ej, $el, $em, $ed, $YYYY
$today = @YEAR & @MON & @MDAY
#$today = 20140101; testing variable

Local $test = SHDay(@YEAR,01,01)
Local $test = SHDay(@YEAR,07,04)
Local $test = SHDay(@YEAR,12,25)

Local $test = VHDay(@YEAR,1,3,2)
Local $test = VHDay(@YEAR,2,3,2)
Local $test = VHDay(@YEAR,9,1,2)
Local $test = VHDay(@YEAR,11,4,5)

Local $test = Easter(@YEAR)
Local $test = GF(@YEAR)
Local $test = May(@YEAR)


If $holiday > 0 Then
        $test = "Today is a Holiday"
    Else
        $test = "Today is not a Holiday"
endIf

MsgBox(0,"",$test,4)



#**********************************************FUNCTIONS**********************************************


 #**********************************************Fixed Holiday Checker**********************************************
Func SHDay($y,$m,$d)
    DD($y,$m,$d)
    Test()
EndFunc

#**********************************************Variable Holiday Checker**********************************************
Func VHDay($y, $m, $n, $dow)
    $1stdayofmonth = _DateToDayOfWeek($y,$m,1)
    $downew = $dow - $1stdayofmonth + $n * 7 + 1
    If $downew > $n * 7 then
        $downew = $downew - 7
    EndIf
    DD($y,$m,$downew)
    Test()
EndFunc


#**********************************************Memorial Day Holiday Checker**********************************************
Func May($y)

local $mi,$mlim,$dow = 2,$m = 5,$mlim = _DateDaysInMonth($y,5), $mondaysinmay = 0

    For $mi = 1 to $mlim step 1
            If _DateToDayOfWeek($y,5,$mi) = 2   Then
                $mondaysinmay = $mondaysinmay + 1
            EndIf
    Next

    $1stdayofmonth = _DateToDayOfWeek($y,5,1)
    $downew = $dow - $1stdayofmonth + $n * 7 + 1

    If $downew > $n * 7 then
        $downew = $downew - 7
    EndIf

    $downew = $mondaysinmay *7 +$downew

    $d = @MDAY
    DD($y,$m,$downew)
    Test()
EndFunc




#**********************************************Easter Mess**********************************************
Func Easter($YYYY)
    $ec = Int($YYYY / 100)
    $en = $YYYY - 19 * int(($YYYY / 19))
    $ek = Int(($ec - 17) / 25)
    $ei = $ec - int($ec / 4) - int(($ec - $ek) / 3) + 19 * $en + 15
    $ei = $ei - 30 * Int($ei / 30)
    $ei = $ei - Int($ei / 28) * (1 - Int($ei / 28) * Int(29 / ($ei + 1)) * Int((21 - $en) / 11))
    $ej = $YYYY + Int($YYYY / 4) + $ei + 2 - $ec + int($ec / 4)
    $ej = $ej - 7 * Int($ej / 7)
    $el = $ei - $ej
    $em = 3 + int(($el + 40) / 44)
    $ed = $el + 28 - 31 * Int($em / 4)
    $gf = ($el + 28 - 31 * Int($em / 4)) - 2
    DD($YYYY,$gf,$ed)
    Test()
    DD($YYYY,$em,$ed)
    Test()
EndFunc


#**********************************************Good Friday Mess**********************************************
Func GF($YYYY)
    $ec = Int($YYYY / 100)
    $en = $YYYY - 19 * int(($YYYY / 19))
    $ek = Int(($ec - 17) / 25)
    $ei = $ec - int($ec / 4) - int(($ec - $ek) / 3) + 19 * $en + 15
    $ei = $ei - 30 * Int($ei / 30)
    $ei = $ei - Int($ei / 28) * (1 - Int($ei / 28) * Int(29 / ($ei + 1)) * Int((21 - $en) / 11))
    $ej = $YYYY + Int($YYYY / 4) + $ei + 2 - $ec + int($ec / 4)
    $ej = $ej - 7 * Int($ej / 7)
    $el = $ei - $ej
    $em = 3 + int(($el + 40) / 44)
    $ed = ($el + 28 - 31 * Int($em / 4)) - 2
    DD($YYYY,$em,$ed)
    Test()
EndFunc


 #**********************************************Date Format Equalizer**********************************************
Func DD($y,$m,$d)
    If $m < 10 then
        $m = 0 & $m
    EndIf
    if $d < 10 then
        $d = 0 & $d
    EndIf
    $testday = $y & $m & $d
    Return $testday
EndFunc

#**********************************************Check If Today is Holiday**********************************************
func Test()
    if $testday = $today Then
        $holiday = $holiday + 1
    EndIf
    return $holiday
EndFunc
Link to comment
Share on other sites

my now works well for use in Brazil and added the function to track the object through the post.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icone.ico
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=Função: Verificar se os correios cumpriram o prazo de entrega.
#AutoIt3Wrapper_Res_Description=Autoit3 3.3.9.4
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Feito por Belini em 16/05/2014
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

; ============================================================================
; Autoit3 3.3.9.4
; Autor: Belini
; Data: 16/05/2014
; Objetivo: Verificar se os correios cumpriram o prazo de entrega.
; ============================================================================

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <Inet.au3>

Global $extrai_inicio, $extrai_final, $confere, $data_fixa[9], $Data_movel[4], $lab_fixa[9], $lab_movel[4]
Global $inp_rast, $Inp_postagem, $Inp_previsao, $inp_entrega, $But_incluir, $gui_principal, $gui_feriados
Global $But_edit_mov, $But_fer_moveis, $inp_alt_entrega, $But_alt_incluir, $Inp_alt_previsao, $nMsg
Global $gui_alt_dados, $inp_alt_dest, $But_alterar, $inp_alt_rast, $Inp_alt_postagem, $sem_dados = 0
Global $le_inp1, $le_inp2, $le_inp3, $le_inp4, $le_inp5, $listv_rast, $inp_dest, $List_rastreio
Global $But_alt_dados, $But_excl_linha

; ====================================================================================================================== Gui principal
$gui_principal = GUICreate("Acompanhamento de entrega dos correios.", 896, 646, -1, -1, -1, $WS_EX_TOPMOST)
GUICtrlCreateGroup("Acompanhamento de entrega dos correios ", 8, 12, 881, 100)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlCreateLabel("Destinatário:", 16, 44, 73, 19)
GUICtrlCreateLabel("Nº rastreio:", 262, 44, 52, 19)
GUICtrlCreateLabel("Dia postagem:", 418, 44, 70, 19)
GUICtrlCreateLabel("Previsão dias:", 569, 44, 80, 19)
GUICtrlCreateLabel("Dia entrega:", 690, 44, 64, 19)
$inp_dest = GUICtrlCreateInput("", 80, 41, 172, 23)
$inp_rast = GUICtrlCreateInput("", 318, 41, 92, 23, $ES_CENTER)
$Inp_postagem = GUICtrlCreateInput("", 490, 41, 68, 23, $ES_CENTER)
$Inp_previsao = GUICtrlCreateInput("", 640, 41, 39, 23, BitOR($ES_AUTOHSCROLL, $ES_CENTER, $ES_NUMBER))
$inp_entrega = GUICtrlCreateInput("", 752, 41, 68, 23, $ES_CENTER)
$But_incluir = GUICtrlCreateButton("Incluir", 828, 38, 51, 25)
$But_alterar = GUICtrlCreateButton("Alterar dados da linha selecionada", 20, 74, 200, 25)
$But_excl_linha = GUICtrlCreateButton("Excluir dados da linha selecionada", 240, 74, 200, 25)
$But_fer_moveis = GUICtrlCreateButton("Editar data dos feriados móveis", 460, 74, 200, 25)
$But_rastrear = GUICtrlCreateButton("Conferir rastreio digitado ou selecionado", 679, 74, 200, 25)

$List_rastreio = GUICtrlCreateListView("                         Nome destinatário|     Nº rastreio|Data que foi postado|Previsão|Data " & _
        "que foi entregue|Dias úteis| Cumpriu prazo", _
        8, 122, 879, 296, BitOR($LVS_SINGLESEL, $LVS_SORTASCENDING, $WS_EX_ACCEPTFILES), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
_GUICtrlListView_SetColumnWidth($List_rastreio, 0, 262)
_GUICtrlListView_SetColumnWidth($List_rastreio, 1, 100)
_GUICtrlListView_SetColumnWidth($List_rastreio, 2, 130)
_GUICtrlListView_SetColumnWidth($List_rastreio, 3, 65)
_GUICtrlListView_SetColumnWidth($List_rastreio, 4, 136)
_GUICtrlListView_SetColumnWidth($List_rastreio, 5, 72)
_GUICtrlListView_SetColumnWidth($List_rastreio, 6, 100)

$listv_rast = GUICtrlCreateListView("                   data|                                                                        local|" & _
        "                             situação  ", 8, 422, 879, 220, BitOR($LVS_SINGLESEL, $LVS_SORTASCENDING), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($listv_rast, 0, 150)
_GUICtrlListView_SetColumnWidth($listv_rast, 1, 500)
_GUICtrlListView_SetColumnWidth($listv_rast, 2, 220)

GUISetState(@SW_SHOW, $gui_principal)
; ====================================================================================================================== Gui principal

; ======================================================================================================================= Gui Feriados
$gui_feriados = GUICreate("                 Editar data dos feriados:", 238, 411, -1, -1, $GUI_SS_DEFAULT_GUI - $WS_SYSMENU, $WS_EX_TOPMOST)
GUICtrlCreateGroup("Feriados móveis ", 8, 8, 223, 129)
GUICtrlCreateGroup("Feriados Fixos ", 8, 145, 223, 217)
$Data_movel[1] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "1", "")
$Data_movel[2] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "2", "")
$Data_movel[3] = IniRead(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "3", "")
$extrai_inicio = StringMid($Data_movel[1], 1, StringInStr($Data_movel[1], "/", 2, 1) - 1)
If StringLen($extrai_inicio) = "" Then $extrai_inicio = @YEAR
$data_fixa[1] = $extrai_inicio & "/01/01"
$data_fixa[2] = $extrai_inicio & "/04/21"
$data_fixa[3] = $extrai_inicio & "/05/01"
$data_fixa[4] = $extrai_inicio & "/09/07"
$data_fixa[5] = $extrai_inicio & "/10/12"
$data_fixa[6] = $extrai_inicio & "/11/02"
$data_fixa[7] = $extrai_inicio & "/11/15"
$data_fixa[8] = $extrai_inicio & "/12/25"
$data_fixa[8] = $extrai_inicio & "/01/01"
$lab_fixa[1] = GUICtrlCreateLabel("01/01/" & $extrai_inicio & " - Confraternização Universal", 17, 171, 200, 18)
$lab_fixa[2] = GUICtrlCreateLabel("21/04/" & $extrai_inicio & " - Tiradentes", 17, 194, 128, 18)
$lab_fixa[3] = GUICtrlCreateLabel("01/05/" & $extrai_inicio & " - Dia do Trabalhador", 17, 217, 170, 18)
$lab_fixa[4] = GUICtrlCreateLabel("09/07/" & $extrai_inicio & " - Independência", 17, 240, 149, 18)
$lab_fixa[5] = GUICtrlCreateLabel("12/10/" & $extrai_inicio & " - Nossa Senhora Aparecida", 17, 263, 209, 18)
$lab_fixa[6] = GUICtrlCreateLabel("02/11/" & $extrai_inicio & " - Finados", 17, 286, 111, 18)
$lab_fixa[7] = GUICtrlCreateLabel("15/11/" & $extrai_inicio & " - Proclamação da República", 17, 309, 210, 18)
$lab_fixa[8] = GUICtrlCreateLabel("25/12/" & $extrai_inicio & " - Natal", 17, 332, 94, 18)
GUICtrlCreateLabel("Carnaval", 112, 32, 61, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlCreateLabel("Sexta feira santa", 112, 64, 112, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlCreateLabel("Corpus Christi", 112, 96, 92, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")

$confere = StringMid($Data_movel[1], 1, StringInStr($Data_movel[1], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
    $confere = inverte_data($Data_movel[1])
Else
    $confere = $Data_movel[1]
EndIf
$lab_movel[1] = GUICtrlCreateInput($confere, 16, 32, 89, 22, $ES_CENTER)

$confere = StringMid($Data_movel[2], 1, StringInStr($Data_movel[2], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
    $confere = inverte_data($Data_movel[2])
Else
    $confere = $Data_movel[2]
EndIf
$lab_movel[2] = GUICtrlCreateInput($confere, 16, 64, 89, 22, $ES_CENTER)

$confere = StringMid($Data_movel[3], 1, StringInStr($Data_movel[3], "/", 2, 1) - 1)
If StringLen($confere) > 2 Then
    $confere = inverte_data($Data_movel[3])
Else
    $confere = $Data_movel[3]
EndIf
$lab_movel[3] = GUICtrlCreateInput($confere, 16, 96, 89, 22, $ES_CENTER)

GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
$But_edit_mov = GUICtrlCreateButton("Editar data dos feriados móveis", 8, 376, 222, 25)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUISetState(@SW_HIDE, $gui_feriados)
; ======================================================================================================================= Gui Feriados

; =================================================================================================================== Gui Altera dados
$gui_alt_dados = GUICreate("Alteração de dados.", 897, 93, -1, 280, $WS_POPUP, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_TOPMOST))
GUICtrlCreateGroup("Alteraração de dados ", 8, 5, 881, 76)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlCreateLabel("Destinatário:", 16, 40, 73, 19)
GUICtrlCreateLabel("Nº rastreio:", 264, 40, 52, 19)
GUICtrlCreateLabel("Dia postagem:", 418, 40, 70, 19)
GUICtrlCreateLabel("Previsão dias:", 569, 40, 80, 19)
GUICtrlCreateLabel("Dia entrega:", 690, 40, 64, 19)

$le_inp1 = GUICtrlRead($inp_dest)
$le_inp2 = GUICtrlRead($inp_rast)
$le_inp3 = GUICtrlRead($Inp_postagem)
$le_inp4 = GUICtrlRead($Inp_previsao)
$le_inp5 = GUICtrlRead($inp_entrega)

$inp_alt_dest = GUICtrlCreateInput($le_inp1, 80, 37, 172, 23)
$inp_alt_rast = GUICtrlCreateInput($le_inp2, 320, 37, 88, 23)
$Inp_alt_postagem = GUICtrlCreateInput($le_inp3, 490, 37, 68, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
$Inp_alt_previsao = GUICtrlCreateInput($le_inp4, 640, 37, 39, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
$inp_alt_entrega = GUICtrlCreateInput($le_inp5, 752, 37, 68, 23, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
$But_alt_dados = GUICtrlCreateButton("Alterar", 828, 34, 51, 25)
GUISetState(@SW_HIDE, $gui_alt_dados)
; =================================================================================================================== Gui Altera dados

atualiza_dados()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $But_fer_moveis
            GUISetState(@SW_HIDE, $gui_principal)
            GUISetState(@SW_SHOW, $gui_feriados)
        Case $But_alterar
            altera_dados()
        Case $But_incluir
            inclui_dados()
            limpa_info()
        Case $But_edit_mov
            edit_feriados()
        Case $But_excl_linha
            exclui_linha()
            limpa_info()
        Case $But_alt_dados
            inclui_dados(1)
            atualiza_dados()
            limpa_info()
        Case $But_rastrear
            rastreio()
    EndSwitch
WEnd

Func rastreio()
    Local $num_linha, $rastreio
    $rastreio = GUICtrlRead($inp_rast)
    SplashTextOn("INFO", "Verificando dados, aguarde...", 230, 30, -1, -1, 33, 12)
    If $rastreio = "" Then
        $num_linha = _GUICtrlListView_GetSelectedIndices($List_rastreio)
        $rastreio = _GUICtrlListView_GetItemText($List_rastreio, Number($num_linha), 1)
    EndIf
    $sUrl = "http://websro.correios.com.br/sro_bin/txect01$.Inexistente?P_LINGUA=001&P_TIPO=002&P_COD_LIS=" & $rastreio
    $html_source = (_INetGetSource($sUrl))
    $html_format = BinaryToString(StringToBinary($html_source, 1), 4)
    $table = StringRegExp($html_format, '(?i)(?s)<tr>.*?<\/tr>\n<tr>(.*?)<\/tr>', 3)
    _ArrayReverse($table)
    SplashOff()
    generateListView($table)
EndFunc   ;==>rastreio

Func generateListView($aArray)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listv_rast))
    Local $soma_dia, $inverte_data, $data_inicial, $data_final, $nome_dest, $ver_final, $ver_inicial, $num_itens = UBound($aArray) - 1

    If $num_itens > 0 Then
        For $i = 0 To $num_itens
            $extract = StringRegExp($aArray[$i], '(?i)(?s)<td.*?>(.*?)<\/td><td.*?>(.*?)<\/td><td.*?><font.*?>(.*?)<\/font><\/td>', 3)
            If (IsArray($extract)) Then
                _GUICtrlListView_AddItem($listv_rast, $extract[0], 0)
                _GUICtrlListView_AddSubItem($listv_rast, $i, $extract[1], 1, 1)
                _GUICtrlListView_AddSubItem($listv_rast, $i, $extract[2], 2, 1)
            EndIf
        Next
        $data_inicial = _GUICtrlListView_GetItemText($listv_rast, 0, 0)
        $data_inicial = StringMid($data_inicial, 1, StringInStr($data_inicial, " ", 2, -1) - 1)
        $inverte_data = inverte_data($data_inicial)
        $soma_dia = _DateAdd('d', 1, $inverte_data)
        $inverte_data = inverte_data($soma_dia)

        $data_final = _GUICtrlListView_GetItemText($listv_rast, $num_itens, 0)
        $data_final = StringMid($data_final, 1, StringInStr($data_final, " ", 2, -1) - 1)

        $nome_dest = GUICtrlRead($inp_dest)

        $ver_final = inverte_data($data_final)
        $ver_inicial = inverte_data($data_inicial)
        If $data_final < $data_inicial Then
            GUICtrlSetData($Inp_postagem, $data_final)
            GUICtrlSetData($inp_entrega, $inverte_data)
        Else
            GUICtrlSetData($Inp_postagem, $inverte_data)
            GUICtrlSetData($inp_entrega, $data_final)
        EndIf
        If StringLen($nome_dest) = 0 Then GUICtrlSetData($inp_dest, "Alguém")

    Else
        MsgBox(4096, 'ERRO', 'Este número de rastreio não é válido', 3)
    EndIf
EndFunc   ;==>generateListView

Func atualiza_dados()
    Local $lista, $i
    Local $aArray = IniReadSection(@ScriptDir & "\Dados.ini", "DADOS")
    Local $conta = UBound($aArray) - 1
    If $conta > 0 Then
        For $i = 1 To $conta
            $lista = $aArray[$i][0] & $aArray[$i][1]
            GUICtrlCreateListViewItem($lista, $List_rastreio)
        Next
    Else
        $sem_dados = 1
    EndIf
EndFunc   ;==>atualiza_dados

Func altera_dados()
    GUISetState(@SW_HIDE, $gui_principal)
    GUISetState(@SW_SHOW, $gui_alt_dados)
    Local $extrai_inicio, $item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
    Local $inf_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 0)
    Local $inf_rast = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 1)
    Local $inf_post = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 2)
    Local $inf_prev = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 3)
    Local $inf_entreg = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 4)

    $extrai_inicio = StringMid($inf_post, 1, StringInStr($inf_post, "/", 2, 1) - 1)
    If StringLen($extrai_inicio) > 2 Then $inf_post = inverte_data($inf_post)

    $extrai_inicio = StringMid($inf_entreg, 1, StringInStr($inf_entreg, "/", 2, 1) - 1)
    If StringLen($extrai_inicio) > 2 Then $inf_entreg = inverte_data($inf_entreg)

    GUICtrlSetData($inp_alt_dest, $inf_dest)
    GUICtrlSetData($inp_alt_rast, $inf_rast)
    GUICtrlSetData($Inp_alt_postagem, $inf_post)
    GUICtrlSetData($Inp_alt_previsao, $inf_prev)
    If $inf_entreg <> "" And $inf_entreg <> "-" Then GUICtrlSetData($inp_alt_entrega, $inf_entreg)
EndFunc   ;==>altera_dados

Func exclui_linha()
    Local $item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
    Local $nome_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel))
    IniDelete(@ScriptDir & "\Dados.ini", "DADOS", $nome_dest)
    _GUICtrlListView_DeleteItem(GUICtrlGetHandle($List_rastreio), $item_sel)
EndFunc   ;==>exclui_linha

Func limpa_info()
    GUICtrlSetData($inp_dest, "")
    GUICtrlSetData($inp_rast, "")
    GUICtrlSetData($Inp_postagem, "")
    GUICtrlSetData($Inp_previsao, "")
    GUICtrlSetData($inp_entrega, "")
    GUICtrlSetData($inp_alt_dest, "")
    GUICtrlSetData($inp_alt_rast, "")
    GUICtrlSetData($Inp_alt_postagem, "")
    GUICtrlSetData($Inp_alt_previsao, "")
    GUICtrlSetData($inp_alt_entrega, "")
EndFunc   ;==>limpa_info

Func edit_feriados()
    Local $ano, $extrai_ano
    GUISetState(@SW_SHOW, $gui_feriados)

    Local $le_fer_1 = GUICtrlRead($lab_movel[1])
    $extrai_final = StringTrimLeft($le_fer_1, StringInStr($le_fer_1, "/", 2, -1))
    If StringLen($extrai_final) > 2 Then $le_fer_1 = inverte_data($le_fer_1)
    If _DateIsValid($le_fer_1) Then
        IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "1", $le_fer_1)
    Else
        MsgBox(4096, "Data inválida", "A data do carnaval não é válida", 3)
        GUICtrlSetData($lab_movel[1], @MDAY & "/" & @MON & "/" & @YEAR)
        WinActivate("Editar data dos feriados:")
        GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
    EndIf

    Local $le_fer_2 = GUICtrlRead($lab_movel[2])
    $extrai_final = StringTrimLeft($le_fer_2, StringInStr($le_fer_2, "/", 2, -1))
    If StringLen($extrai_final) > 2 Then $le_fer_2 = inverte_data($le_fer_2)
    If _DateIsValid($le_fer_2) Then
        IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "2", $le_fer_2)
    Else
        MsgBox(4096, "Data inválida", "A data sexta feira santa não é válida", 3)
        GUICtrlSetData($lab_movel[2], @MDAY & "/" & @MON & "/" & @YEAR)
        WinActivate("Editar data dos feriados:")
        GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
    EndIf

    Local $le_fer_3 = GUICtrlRead($lab_movel[3])
    $extrai_final = StringTrimLeft($le_fer_3, StringInStr($le_fer_3, "/", 2, -1))
    If StringLen($extrai_final) > 2 Then $le_fer_3 = inverte_data($le_fer_3)
    If _DateIsValid($le_fer_3) Then
        IniWrite(@ScriptDir & "\Feriados.ini", "FERIADOS MOVEIS", "3", $le_fer_3)
    Else
        MsgBox(4096, "Data inválida", "A data de corpus christi não é válida", 3)
        GUICtrlSetData($lab_movel[3], @MDAY & "/" & @MON & "/" & @YEAR)
        WinActivate("Editar data dos feriados:")
        GUICtrlSetState($lab_movel[1], $GUI_FOCUS)
    EndIf

    $extrai_ano = StringTrimLeft($le_fer_1, StringInStr($le_fer_1, "/", 2, -1))
    If StringLen($extrai_ano) > 2 Then
        $ano = $extrai_ano
    Else
        $extrai_ano = StringMid($le_fer_1, 1, StringInStr($le_fer_1, "/", 2, 1) - 1)
        If StringLen($extrai_ano) > 2 Then
            $ano = $extrai_ano
        Else
            $ano = @YEAR
        EndIf
    EndIf

    GUICtrlSetData($lab_fixa[1], "01/01/" & $ano & " - Confraternização Universal")
    GUICtrlSetData($lab_fixa[2], "21/04/" & $ano & " - Tiradentes")
    GUICtrlSetData($lab_fixa[3], "01/05/" & $ano & " - Dia do Trabalhador")
    GUICtrlSetData($lab_fixa[4], "09/07/" & $ano & " - Independência")
    GUICtrlSetData($lab_fixa[5], "12/10/" & $ano & " - Nossa Senhora Aparecida")
    GUICtrlSetData($lab_fixa[6], "02/11/" & $ano & " - Finados")
    GUICtrlSetData($lab_fixa[7], "15/11/" & $ano & " - Proclamação da República")
    GUICtrlSetData($lab_fixa[8], "25/12/" & $ano & " - Natal")
    If _DateIsValid($le_fer_1) And _DateIsValid($le_fer_2) And _DateIsValid($le_fer_3) Then
        GUISetState(@SW_HIDE, $gui_feriados)
        GUISetState(@SW_SHOW, $gui_principal)
    EndIf
EndFunc   ;==>edit_feriados

Func inclui_dados($opt = 0)
    Local $item_sel, $inf_dest, $prazo, $extrai_inicio, $extrai_final
    Local $1, $2, $3, $4, $5, $6, $7, $dados, $data_ini, $data_fim

    If $opt = 1 Then
        $1 = GUICtrlRead($inp_alt_dest)
        $2 = GUICtrlRead($inp_alt_rast)
        $3 = GUICtrlRead($Inp_alt_postagem)
        $4 = GUICtrlRead($Inp_alt_previsao)
        $5 = GUICtrlRead($inp_alt_entrega)
    Else
        $1 = GUICtrlRead($inp_dest)
        $2 = GUICtrlRead($inp_rast)
        $3 = GUICtrlRead($Inp_postagem)
        $4 = GUICtrlRead($Inp_previsao)
        $5 = GUICtrlRead($inp_entrega)
    EndIf

    $extrai_final = StringTrimLeft($3, StringInStr($3, "/", 2, -1))
    If StringLen($extrai_final) > 2 Then
        $data_ini = inverte_data($3)
    Else
        $data_ini = $3
    EndIf

    $extrai_final = StringTrimLeft($5, StringInStr($5, "/", 2, -1))
    If StringLen($extrai_final) > 2 Then
        $data_fim = inverte_data($5)
    Else
        $data_fim = $5
    EndIf

    If _DateIsValid($data_ini) = 1 And _DateIsValid($data_fim) = 1 Then
        $6 = dias_uteis($data_ini, $data_fim)
    Else
        If _DateIsValid($data_fim) = 0 Then $6 = "-"
        If _DateIsValid($data_ini) = 0 Then
            GUICtrlSetData($Inp_alt_postagem, @MDAY & "/" & @MON & "/" & @YEAR)
            GUICtrlSetData($Inp_postagem, @MDAY & "/" & @MON & "/" & @YEAR)
            MsgBox(4096, "ERRO!", "A data de postagem não é válida, digite novamente!", 3)
        EndIf

        If _DateIsValid($5) = 0 Then $5 = "-"
    EndIf

    If $4 <> "" And $6 <> "" Then
        $7 = $4 - $6
    Else
        If $6 = "" Then $6 = "-"
    EndIf

    If $7 >= 0 And $7 <> "" And $6 <> "-" Then
        $prazo = "sim"
    Else
        If $7 = "" Or $6 = "-" Then
            $prazo = "-"
        Else
            $prazo = "Não"
        EndIf
    EndIf

    If $1 <> "" And $2 <> "" And $3 <> "" And $4 <> "" Then
        If $opt = 1 And _DateIsValid($data_ini) = 1 Then
            $item_sel = _GUICtrlListView_GetSelectedIndices($List_rastreio)
            $inf_dest = _GUICtrlListView_GetItemText($List_rastreio, Number($item_sel), 0)
            IniDelete(@ScriptDir & "\Dados.ini", "DADOS", $inf_dest)
            GUISetState(@SW_SHOW, $gui_principal)
            GUISetState(@SW_HIDE, $gui_alt_dados)
            _GUICtrlListView_DeleteAllItems($List_rastreio)
        EndIf

        $extrai_inicio = StringMid($3, 1, StringInStr($3, "/", 2, 1) - 1)
        If StringLen($extrai_inicio) > 2 Then $3 = inverte_data($3)

        $extrai_inicio = StringMid($5, 1, StringInStr($5, "/", 2, 1) - 1)
        If StringLen($extrai_inicio) > 2 Then $5 = inverte_data($5)

        $dados = $1 & "|" & $2 & "|" & $3 & "|" & $4 & "|" & $5 & "|" & $6 & "|" & $prazo
        If $opt = 0 Then GUICtrlCreateListViewItem($dados, $List_rastreio)
        GUICtrlSetData($inp_dest, "")
        GUICtrlSetData($inp_rast, "")
        GUICtrlSetData($Inp_previsao, "")
        GUICtrlSetData($inp_entrega, "")
        GUICtrlSetData($Inp_postagem, @MDAY & "/" & @MON & "/" & @YEAR)
        IniWrite(@ScriptDir & "\Dados.ini", "DADOS", $1, "|" & $2 & "|" & $3 & "|" & $4 & "|" & $5 & "|" & $6 & "|" & $prazo)
    Else
        If $1 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher o nome do destinatário para continuar!", 3)
        If $2 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher o número do rastreio para continuar!", 3)
        If $3 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher a data da postagem para continuar!", 3)
        If $4 = "" Then MsgBox(4096, "ERRO!", "É preciso preecher a previsão de entrega dos correios continuar!", 3)
    EndIf
EndFunc   ;==>inclui_dados

Func inverte_data($data)
    Local $corta_inicio = StringTrimLeft($data, StringInStr($data, "/", 2, 1) - 1)
    Local $extrai_meio = StringMid($corta_inicio, 1, StringInStr($corta_inicio, "/", 2, -1))
    Local $extrai_inicio = StringMid($data, 1, StringInStr($data, "/", 2, 1) - 1)
    Local $extrai_final = StringTrimLeft($data, StringInStr($data, "/", 2, -1))
    Local $data_invertida = $extrai_final & $extrai_meio & $extrai_inicio
    Return $data_invertida
EndFunc   ;==>inverte_data

Func dias_uteis($data_ini, $data_fim)
    Local $conta = 0, $i, $i2, $i3, $feriado, $nova_data, $separa_data
    Local $dia_semana, $diferenca = _DateDiff('D', $data_ini, $data_fim)
    For $i = 0 To $diferenca
        $nova_data = _DateAdd('D', $i, $data_ini)
        $feriado = 0
        For $i2 = 1 To 8
            If $data_fixa[$i2] = $nova_data Then $feriado = 1
        Next
        If $feriado = 0 Then
            For $i3 = 1 To 3
                If $Data_movel[$i3] = $nova_data Then $feriado = 1
            Next
        EndIf
        $separa_data = StringSplit($nova_data, "/")
        $dia_semana = _DateToDayOfWeekISO($separa_data[1], $separa_data[2], $separa_data[3])
        If $dia_semana >= 1 And $dia_semana <= 5 And $feriado = 0 Then
            $conta += 1
        EndIf
    Next
    Return $conta
EndFunc   ;==>dias_uteis

Source:  https://www.dropbox.com/s/s5ms4abzs0n8hw0/Source.rar

Edited by Belini
Link to comment
Share on other sites

could always use excel, NETWORKDAYS(), make a range for you're holidays and that way you're spreadsheet will auto update.

Could use autoit to work with excel to take the number of workdays, also to put in any holidays etc... i know nothing what you're after but just another approach which is VERY simple to do in excel quickly and can still use autoit to work with it thanks to water.

Edited by 13lack13lade
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...