#!c:\apl\perl\bin\perl.exe # rotina : enr.pl # use ProductCenter; use Getopt::Std; use DBI; print "\n\n\t================\n"; print "\n\tRotina Global EN\n"; print "\n\tVersao 1008\n\n"; # ----------------------------------------------------------------------------------- # Variables my %config; my $dbname=shift; if ($dbname eq 'JLEPRC') { %config = ( USER => cms, PASS => cancun2006, HOST => mjhp00, SID => JLEPRC, PORT => 5800, SITE => REFRIGERACAO, DEBUG => 1); $dbuser = 'cms'; $dbpass = 'cms'; $ENV{ORACLE_SID} = 'JLEPRC'; $ENV{ORACLE_HOME} = 'c:\oracle\ora81'; $ENV{EPC_DISABLED} = 'TRUE'; $ENV{ORAPIPES} = 'V2'; $my_user = 'root'; $my_pass = ''; $my_port = ''; $my_host = '159.155.191.187'; $my_db = 'jle'; } else { %config = ( USER => , PASS => , HOST => , SID => , PORT => 0, SITE => , DEBUG => 1); } sub connectToServer { # ---open PRC--- # # uso: # funcao: Estabelecer conexao com PRC ($config{'DEBUG'} == 1 ? print "\nConnecting PRC8...".$config{'SID'}."\n" : ""); my $cnxn = new ProductCenter::Cnxn; $cnxn->SetAutoPrintError(); $cnxn->ClearAbortOnError(); if($cnxn->GetStatus() != 0) { $cnxn->PrintError(); exit; } $cnxn->SetDb($config{'SID'}); $cnxn->SetServerHost($config{'HOST'}); $cnxn->SetPortNumber($config{'PORT'}); $cnxn->SetClientLocale("en_US"); $cnxn->ConnectAsUser($config{'USER'},$config{'PASS'}); if($cnxn->GetStatus() != 0) { $cnxn->PrintError(); exit; } ($config{'DEBUG'} == 1 ? print "ok.\n" : ""); return $cnxn; } # ----------disconnect---------- # uso: Disconnect($cnxn); # funcao: Desconectar de PRC # sub disconnect { my $cnxn = shift; ($config{'DEBUG'} == 1 ? print "\nDisconnecting PRC8..." : ""); $cnxn->Disconnect(); ($config{'DEBUG'} == 1 ? print "ok.\n" : ""); exit(0); } sub closeDB { # closeDB() # uso: closeDB(); # funcao: Fechar conexao estabelecida previamente com openDB() my $dbo = shift; $dbo->disconnect(); } sub regError { my $dbo=shift; my $dbm=shift; my $msg_code = shift; my $file_id = shift; my $id = shift; my $dbname=shift; my $dt_reg; my $db_parse_sub; my $plc; my %hoje; # ($config{'DEBUG'} == 1 ? print "\nregError." : ""); %hoje = getDate(); $dt_reg = "$hoje{'ANO'}$hoje{'MES'}$hoje{'DIAMES'}$hoje{'HORA'}$hoje{'MIN'}$hoje{'SEC'}"; $sql = "select plc from cms_dfm where id='$id'"; $db_parse_sub = $dbo->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbo->errstr; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbo->errstr; $plc = $db_parse_sub->fetchrow_array; $sql = "select msg from ik_msg where msg_code='$msg_code'"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr; $msg = $db_parse_sub->fetchrow_array; $sql = "insert into ik_log (id,file_id,plc,tech_center,msg_code,msg,msg_status,dt_reg) values ('$id','$file_id','$plc','$dbname','$msg_code','$msg',0,'$dt_reg')"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr; } sub getDate { my %hoje; # ($config{'DEBUG'} == 1 ? print "\ngetDate" : ""); ($sec,$min,$hora,$diames,$mes,$ano,$diasemana,$diaano,$verao) = localtime; $hoje{'SEC'} = $sec; $hoje{'MIN'} = $min; $hoje{'HORA'} = $hora; $hoje{'DIAMES'} = $diames; $hoje{'MES'} = $mes+1; $hoje{'ANO'} = $ano + 1900; $hoje{'DIASEMANA'} = $diasemana; $hoje{'DIAANO'} = $diaano; $hoje{'VERAO'} = $verao; $hoje{'NOMEDIA'} = '?'; if ($diasemana == 0) { $hoje{'NOMEDIA'} = 'Domingo'; } elsif ($diasemana == 1) { $hoje{'NOMEDIA'} = 'Segunda-feira'; } elsif ($diasemana == 2) { $hoje{'NOMEDIA'} = 'Terça-feira'; } elsif ($diasemana == 3) { $hoje{'NOMEDIA'} = 'Quarta-feira'; } elsif ($diasemana == 4) { $hoje{'NOMEDIA'} = 'Quinta-feira'; } elsif ($diasemana == 5) { $hoje{'NOMEDIA'} = 'Sexta-feira'; } elsif ($diasemana == 7) { $hoje{'NOMEDIA'} = 'Sábado'; } ($config{'DEBUG'} == 1 ? print "\n\t\t\tgetDate\n" : ""); return %hoje; } # --- verifica por erros em rotinas no PRC sub chkError { my $cnxn=shift; if ($cnxn->GetStatus() != SUCCESS) { printf "%d: %s\n",$cnxn->GetStatus(),$cnxn->GetStatusMesg(); } } # --- registra no banco de dados para posterior envio de email sub sendEmail { my $dbo=shift; my $dbm=shift; my $en_nbr=shift; my $msg=shift; my $msg_code=shift; my $dest=shift; my $dbname=shift; my $db_parse_sub; my $chk; my $chk1; my %hoje; my $dt_zero; ($config{'DEBUG'} == 1 ? print "\n\tsendEmail" : ""); %hoje = getDate(); $dt_reg = $hoje{'ANO'} . '-' . $hoje{'MES'} . '-' . $hoje{'DIAMES'}; $dt_zero = $dt_reg . ' 00:00:00'; $chk = 0; ($config{'DEBUG'} == 1 ? print "...s" : ""); $sql = "select count(file_id_p) from ik_gen_log where file_id_p='EN $en_nbr'"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; $chk = $db_parse_sub->fetchrow_array; if ($chk > 0) { $sql = "select count(file_id_p) from ik_gen_log where file_id_p='EN $en_nbr' and dt_envio>='$dt_reg'"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; $chk1 = $db_parse_sub->fetchrow_array; if ($chk1 <1) { ($config{'DEBUG'} == 1 ? print "...d" : ""); $sql = "delete from ik_gen_log where file_id_p='EN $en_nbr'"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; ($config{'DEBUG'} == 1 ? print "...i" : ""); $sql = "insert into ik_gen_log (file_id_p,msg,msg_code,tech_center,email,dt_registro,apl) values ('EN $en_nbr','$msg','$msg_code','$dbname','$dest','$dt_reg','GEN')"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; ($config{'DEBUG'} == 1 ? print "...ok\n" : ""); } else { ($config{'DEBUG'} == 1 ? print "...email ja enviado hoje." : ""); } } else { ($config{'DEBUG'} == 1 ? print "...i" : ""); $sql = "insert into ik_gen_log (file_id_p,msg,msg_code,tech_center,email,dt_registro,apl) values ('EN $en_nbr','$msg','$msg_code','$dbname','$dest','$dt_reg','GEN')"; $db_parse_sub = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_sub->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; ($config{'DEBUG'} == 1 ? print "...ok\n" : ""); } } # ====================================Main program============================= ($config{'DEBUG'} == 1 ? print "\nConnectin MySQL $my_db..." : ""); my $db_mysql = "dbi:mysql:$my_db"; ($config{'DEBUG'} == 1 ? print "\n\t\tDados: User_name: $my_db , User_pass: xxx" : ""); my $dbm = DBI->connect($db_mysql, $my_user, $my_pass) || die "Unale to connect to $my_db: $DBI::errstr\n"; ($config{'DEBUG'} == 1 ? print "\nconnected.\n" : ""); ($config{'DEBUG'} == 1 ? print "\nConnectin Oracle $dbname..." : ""); my $db_oracle = "dbi:Oracle:$dbname"; ($config{'DEBUG'} == 1 ? print "\n\t\tDados: User_name: $dbuser , User_pass: xxx" : ""); my $dbo = DBI->connect($db_oracle, $dbuser, $dbpass) || die "Unale to connect to $dbname: $DBI::errstr\n"; ($config{'DEBUG'} == 1 ? print "\nconnected.\n" : ""); my $mydata; my $cnxn; $cnxn = connectToServer(); chkError($cnxn); my $db_parse_en; my $db_exec_en; my $db_parse; my $db_exec; my $db_parse_aux; my $db_exec_aux; my $sql; my $db_parse_ulk; my $db_exec_ulk; my $pacote_id_ulk; my $base_ulk; my $link_ulk; my $tail_ulk; my $head_ulk; my $tail_name_ulk; my $tail_class_ulk; my $en_nbr; my $status_code; my $status_code_prc; my $item_nbr; my $item_name; my $full_name; my $email; my $gen_upload; my $tech_center; my $userid; my $pacote; my $pacote_file_id; my $pacote_file_title; my $pacote_id; my $pacote_class_id; my $pacote_class_name; my $pacote_status_code; my $pacote_anterior; my $project; my $project_class_id; my $project_class_name; my $project_file_id; my $project_file_title; my $project_id; my $project_status_code; my $desenho; my $desenho_file_id; my $desenho_file_title; my $desenho_id; my $desenho_class_id; my $desenho_class_name; my $desenho_class_id_alt; my $desenho_class_name_alt; my $desenho_class_id_alt1; my $desenho_class_name_alt1; my $desenho_status_code; my $originator; my $chk_a; my $item_pacote; my $item_project; my $item_desenho; my $base; my $link; my $child; my $i; my $count; my $head; my $tail; my $tail_name; my $erro; my $aux; my $pdf_name; my $pdf_pc; my $desenho_plc; my $pdf; my $plc; my $projeto = '-'; my $saop; my $msg1 = 'Nao e possivel criar pacote EN no PRC se esta nao estiver IP no Global EN'; my $msg2 = 'Nao e possivel criar project no PRC se a EN nao estiver IP no Global EN'; my $msg3 = 'Nao e possivel vincular (link) desenho no PRC se a EN nao estiver IP no Global EN'; my $msg4 = 'Global EN esta em IA ou FA e PRC In Progress'; my $msg5 = 'Falha na Aprovacao do Item.'; my $msg6 = 'Desenho inexistente.'; my $msg7 = 'Nao e possivel vincular (link) project no PRC se a EN nao estiver IP no Global EN'; my $msg8 = 'Nao existe PDF com revisao ou versao igual ao DRW'; my $msg9 = 'Nao e possivel alteracoes em Item que nao estaja IP'; my $msg10= 'Nao e possivel vincular (link) pacote com project se ambos nao estiverem em IP'; # ################################################################################################### # --- Processando apenas os nomes das EN ($config{'DEBUG'} == 1 ? print "\n\t\t\tProcessando Dabatase: $dbname\n" : ""); # pesquisa por todas as ocorrencias distintas em Global EN $sql = "select distinct(en_nbr) from ik_gen_tmp"; $db_parse_en = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse_en->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; # para cada ocorrencia, faca: while ( ($en_nbr)=$db_parse_en->fetchrow_array) { #--- looping princial --- # ---Identifica Tech Center e classes--- print "\n\n\n\n - - - - - - - - - - - - - - - - - - - - - - - - - -\n"; $erro = 0; # $sql = "delete from ik_gen_log where file_id_p='EN $en_nbr'"; # $db_parse = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; # $db_parse->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; # monta lista_gen para posteriro comparacao e eliminacao de algum item_nbr ($config{'DEBUG'} == 1 ? print "Montando lista Item_Nbr do GEN\n" : ""); $sql = "select item_nbr from ik_gen_tmp where status_code<>'DEL' and en_nbr='$en_nbr'"; $db_parse = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; my $lista_gen; while ( ($item_nbr)=$db_parse->fetchrow_array) { $lista_gen = $lista_gen . " " . $item_nbr; } # pesquisa por todas as ocorrencias em Global EN de determinado EN_NBR $sql = "select en_nbr,status_code,item_nbr,item_name,full_name,email,gen_upload,tech_center,userid from ik_gen_tmp where en_nbr='$en_nbr'"; $db_parse = $dbm->prepare($sql) || die "Falha em Prepare $sql.Erro: " . $dbm->errstr . "\n"; $db_parse->execute || die "Falha em Execute $sql.Erro: " . $dbm->errstr . "\n"; # para cada ocorrencia, faca: while ( ($en_nbr,$status_code,$item_nbr,$item_name,$full_name,$email,$gen_upload,$tech_center,$userid)=$db_parse->fetchrow_array) { #--- looping princial --- if ($tech_center eq "JOIN") { $pacote_class_name = "CMS:Projects:Global EN"; $sql = "select class_id from cms_class where name='$pacote_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER JOIN. Pacote class id: $pacote_class_id\n" : ""); $project_class_name = "CMS:Parts:Componentes"; $sql = "select class_id from cms_class where name='$project_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $project_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER JOIN. Project class id: $project_class_id\n" : ""); $desenho_class_name = "CMS:Files:Tecnologia:Produtos:Desenhos"; $sql = "select class_id from cms_class where name='$desenho_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER JOIN. Desenho class id: $desenho_class_id_alt1\n" : ""); $desenho_class_name_alt1 = "CMS:Files:Tecnologia:CA Manaus:Desenhos"; $sql = "select class_id from cms_class where name='$desenho_class_name_alt1'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_class_id_alt1 = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER JOIN. Desenho class id: $desenho_class_id\n" : ""); } if ($tech_center eq "MANA") { $pacote_class_name = "CMS:Projects:Global EN"; $sql = "select class_id from cms_class where name='$pacote_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER MANA. Pacote class id: $pacote_class_id\n" : ""); $project_class_name = "CMS:Parts:Componentes"; $sql = "select class_id from cms_class where name='$project_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $project_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER MANA. Project class id: $project_class_id\n" : ""); $desenho_class_name = "CMS:Files:Tecnologia:CA Manaus:Desenhos"; $sql = "select class_id from cms_class where name='$desenho_class_name'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_class_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER MANA. Desenho class id: $desenho_class_id\n" : ""); $desenho_class_name_alt = "CMS:Files:Tecnologia:Produtos:Desenhos"; $sql = "select class_id from cms_class where name='$desenho_class_name_alt'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_class_id_alt = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "TECH CENTER MANA. Desenho class id: $desenho_class_id\n" : ""); } $saop = $tech_center; if ($status_code eq 'DEL') { $pacote_file_id = "EN " . $en_nbr; $pacote_file_title = $pacote_file_id; $pacote = ""; $project = ""; $desenho = ""; # ----------PACOTE---------- # ---Verifica se pacote nao existe. Caso positivo, criar.--- ($config{'DEBUG'} == 1 ? print "\n\t\t\tDEL PACOTE\n" : ""); $chk_a = 0; $sql = "select count(id) from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { # ---Pacote existe. $pacote = "Existente"; $sql = "select id from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_id = $db_parse_aux->fetchrow_array; # ----------DEL---------- # ---Se no GEN status code=DEL, entao unlink no pacote e delete no pacote--- # ---Pacote foi eliminado no GEN---Fazer o Unlink entre Pacote e Project, e Eliminar Pacote--- #$item_project = new ProductCenter::Item($cnxn,int $pacote_id); # ---Mostrar Link ($config{'DEBUG'} == 1 ? print "Lendo valores de Links\n" : ""); $base = new ProductCenter::Item($cnxn,int $pacote_id); $base->GetLinkCount("Child",$count); for ($i = 0; $i < $count; $i++) { $link = $base->GetLink("Child",$i); $head = $link->GetHead(); $tail = $link->GetTail(); print "\n\t\t\tHeader: " . $head->GetAttr("FILE_ID") . "\n"; print "\n\t\t\tTail: " . $tail->GetAttr("FILE_ID") . "\n"; ($config{'DEBUG'} == 1 ? print "Executando UnLinks\n" : ""); $base->RemoveLink($link); $base->Alter(); } } } else # DEL { # #################################################################################################################### # ---Define Status inicial--- if ($status_code eq "IA" || $status_code eq "FA") { $status_code_prc = "In Approval"; } elsif ($status_code eq "REL") { $status_code_prc = "Released"; } else { $status_code_prc = "In Progress"; } $project_file_id = $item_nbr; $project_file_title = $item_name; $originator = "$userid"; #"CMS DBA"; $pacote_file_id = "EN " . $en_nbr; $pacote_file_title = $pacote_file_id; $pacote = ""; $project = ""; $desenho = ""; $desenho_file_id = $project_file_id . ".drw"; # ----------EMAIL---------- # ---identifica usuario e email--- $sql = "select count(user_name) from cms_users where login_name='$userid'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { $sql = "select user_name from cms_users where login_name='$userid'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $originator = $db_parse_aux->fetchrow_array; } # ----------PACOTE----------###############--------------- # ---Verifica se pacote nao existe. Caso positivo, criar.--- ($config{'DEBUG'} == 1 ? print "\n\t\t\tPACOTE\n" : ""); $chk_a = 0; $sql = "select count(id) from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { # ---Pacote existe. $pacote = "Existente"; $sql = "select id from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_id = $db_parse_aux->fetchrow_array; $sql = "select status_code from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_status_code = $db_parse_aux->fetchrow_array; if ($status_code_prc eq 'In Approval' and $pacote_status_code eq 'In Progress') { $erro = 2; # Status Code em GEN = IA ou FA e PRC In Progress. ($config{'DEBUG'} == 1 ? print "GEN: $status_code, PRC: $pacote_status_code\n" : ""); ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg4\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg4,15,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg4,15,$email,$tech_center); next; # salta para proximo item do looping } elsif ($status_code_prc eq 'Released' and $pacote_status_code eq 'In Progress') { $erro = 1; # Status code do Pacote e da EN nao estao corretos ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg9\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg9,15,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg9,15,$email,$tech_center); next; # salta para proximo item do looping } elsif ($status_code_prc eq 'Released' and $pacote_status_code eq 'In Approval') { $erro = 5; # Status code do Pacote e da EN nao estao corretos next; # salta para proximo item do looping } # sincroniza titulo, exceto RIOC if ($tech_center ne "RIOC") { ($config{'DEBUG'} == 1 ? print "Sincronizando Titulo\n" : ""); $item_pacote = new ProductCenter::Item($cnxn,int $pacote_id); $item_pacote->SetAttr("FILE_TITLE","$pacote_file_title"); $item_pacote->Alter(); # $msg_code = 17; # regError($msg_code,$pacote_file_id,$pacote_id,$tech_center,$dbm); } # monta lista_prc para posterior comparacao e eliminacao de algum project ($config{'DEBUG'} == 1 ? print "Montando lista Child Prc\n" : ""); $base = new ProductCenter::Item($cnxn,int $pacote_id); $base->GetLinkCount("Child",$count); my @lista_prc; my $file_name; for ($i = 0; $i < $count; $i++) { $link = $base->GetLink("Child",$i); $tail = $link->GetTail(); $file_name = $tail->GetAttr("FILE_ID"); if ($file_name != '%A%') { print "\n\t\t\tTail: " . $file_name . "\n"; $lista_prc[$i].= $file_name; # if ($i < ($count-1) ) # { # $lista_prc[$i].= ","; # } } } print "Desvinculando:\n"; print @lista_prc . "\n"; foreach $item (@lista_prc) { ($config{'DEBUG'} == 1 ? print "chk link $item..." : ""); $chk = index($lista_gen,$item,0); if ($chk > -1) { print "existe\n"; } else { # desvincula item print "Nao Existe!!!\n"; # $sql = "select id from cms_dfm where id='$pacote_id'"; # $db_parse_ulk = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); # $db_exec_ulk = $db_parse_ulk->execute or die("Falha em SQL Exec.\n"); # $pacote_id_ulk = $db_parse_ulk->fetchrow_array; # ($config{'DEBUG'} == 1 ? print "\nUnLink do item: \n" : ""); $base_ulk = new ProductCenter::Item($cnxn,int $pacote_id); $base_ulk->GetLinkCount("Child",$count); ($config{'DEBUG'} == 1 ? print "Pesquisando Projects [$item] child de [$pacote_file_id] " : ""); for ($i = 0; $i < $count; $i++) { print "\n\tItem: $item,i: $i\n"; print "\tlink_ulk: GetLink\n"; $link_ulk = $base_ulk->GetLink("Child",$i); print "\thead_ulk:GetHead\n"; $head_ulk = $link_ulk->GetHead(); print "\ttail_ulk:GetTail\n"; $tail_ulk = $link_ulk->GetTail(); $tail_name_ulk = $tail_ulk->GetAttr("FILE_ID"); $tail_class_ulk = $tail_ulk->GetAttr("CLASS"); # print "\nCLass: $tail_class_ulk\n"; # ($config{'DEBUG'} == 1 ? print "...$tail_name_ulk\n" : ""); if ($tail_name_ulk eq $item and $tail_class_ulk eq $project_class_name) { print "\n\t\t\tHeader: " . $head_ulk->GetAttr("FILE_ID") . "\n"; print "\n\t\t\tTail: " . $tail_ulk->GetAttr("FILE_ID") . "\n"; print "\n\t\t\tClass: $tail_class_ulk\n"; ($config{'DEBUG'} == 1 ? print "\n\t\t\tExecutando UnLink\n\n" : ""); print "\n\t\t\t\tremovido."; $base_ulk->RemoveLink($link_ulk); $base_ulk->Alter(); $i = $count; } } } # desvincula item } } else { # ---Pacote nao existe. Criar novo.--- $pacote = "Novo"; $pacote_status_code = "In Progress"; if ($status_code_prc eq $pacote_status_code) { $item_pacote = new ProductCenter::Item($cnxn,$pacote_class_name); $item_pacote->SetAttr("FILE_ID","$pacote_file_id"); $item_pacote->SetAttr("FILE_TITLE","$pacote_file_title"); $item_pacote->SetAttr("PREPARER","$originator"); if ($tech_center eq 'SAOP') { $item_pacote->SetAttr("PROJETISTA_RESPONSAVEL_ME","$originator"); $item_pacote->SetAttr("PROJETO","$projeto"); } $item_pacote->Add(); chkError($cnxn); # $msg_code = 11; # regError($msg_code,pacote_file_id,0,$tech_center,$dbm); } else { $erro = 1; # Status Code em GEN nao IP ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg1\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg1,11,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg1,11,$email,$tech_center); next; # salta para proximo item do looping } } ($config{'DEBUG'} == 1 ? print "Pacote $pacote..." : ""); # ---Verifica se pacote existe. Caso positivo, le ID,senao registra erro $chk_a = 0; $sql = "select count(id) from cms_dfm where file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { $sql = "select id from cms_dfm where file_stat=1 and file_id='$pacote_file_id' and class_id='$pacote_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $pacote_id = $db_parse_aux->fetchrow_array; } else { $msg_code = 11; regError($dbo,$dbm,$msg_code,$pacote_file_id,0,$tech_center); } ($config{'DEBUG'} == 1 ? print "\nPacote Name: $pacote_file_id e ID: $pacote_id\n" : ""); # ----------PROJECT----------####################--------- # ---Verifica se project nao existe. Caso positvo, criar.--- ($config{'DEBUG'} == 1 ? print "\n\t\t\tPROJECT\n" : ""); $chk_a = 0; $sql = "select count(id) from cms_dfm where file_stat=1 and file_id='$project_file_id' and class_id='$project_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { # ---Project existe. $project = "Existente"; $sql = "select id from cms_dfm where file_stat=1 and file_id='$project_file_id' and class_id='$project_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $project_id = $db_parse_aux->fetchrow_array; $sql = "select status_code from cms_dfm where file_stat=1 and file_id='$project_file_id' and class_id='$project_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $project_status_code = $db_parse_aux->fetchrow_array; if ($status_code_prc eq 'In Progress' and $project_status_code eq 'In Progress') { ($config{'DEBUG'} == 1 ? print "Criando Link entre $project_file_id and $desenho_file_id\n" : ""); # sincroniza titulo, exceto RIOC if ($tech_center ne "RIOC") { ($config{'DEBUG'} == 1 ? print ".Sincronizando Titulo\n" : ""); $item_project = new ProductCenter::Item($cnxn,int $project_id); $item_project->SetAttr("FILE_TITLE","$project_file_title"); $item_project->Alter(); # $msg_code = 17; # regError($msg_code,project_file_id,$project_id,$tech_center,$dbm); } } elsif ($status_code_prc eq 'Released' and $project_status_code eq 'In Progress') { $erro = 1; # Status code do desenho ou Pacote nao esta IP ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg7\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg7,14,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg7,14,$email,$tech_center); next; # salta para proximo item do looping } } else { if ($project_file_title ne '') { # ---Project nao existe. Criar novo.--- $project = "Novo"; $project_status_code = "In Progress"; if ($pacote_status_code eq 'In Progress') { ($config{'DEBUG'} == 1 ? print "\nNovo Project $project_file_id \nem $project_class_name\ntitulo $project_file_title\n autor $originator\n" : ""); $item_project = new ProductCenter::Item($cnxn,$project_class_name); $item_project->SetAttr("FILE_ID","$project_file_id"); $item_project->SetAttr("FILE_TITLE","$project_file_title"); $item_project->SetAttr("PREPARER","$originator"); $item_project->Add(); #chkError($cnxn); # $msg_code = 11; # regError($msg_code,project_file_id,0,$tech_center,$dbm); } else { $erro = 1; # Status Code em GEN nao IP ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg2\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg2,11,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg2,11,$email,$tech_center); next; # salta para proximo item do looping } } } ($config{'DEBUG'} == 1 ? print "Project $project..." : ""); # ---Verifica se project existe. Caso positivo, le ID,senao registra erro $chk_a = 0; $sql = "select count(id) from cms_dfm where file_stat=1 and file_id='$project_file_id' and class_id='$project_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { if ($project_status_code eq 'In Progress') { $sql = "select id from cms_dfm where file_stat=1 and file_id='$project_file_id' and class_id='$project_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $project_id = $db_parse_aux->fetchrow_array; ($config{'DEBUG'} == 1 ? print "Executando LINK\n" : ""); $link = new ProductCenter::Link($cnxn,"Child"); $base = new ProductCenter::Item($cnxn,int $pacote_id); $child = new ProductCenter::Item($cnxn,int $project_id); $base->AddTailLink($link,$child); $base->Alter(); # $msg_code = 14; # regError($msg_code,desenho_file_id,$desenho_id,$tech_center,$dbm); } elsif ($project_status_code eq 'In Approval' and $status_code_prc eq 'Released') { } else { $erro = 1; # nao pode ser criado link se Project nao IP ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg10\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg10,14,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg10,14,$email,$tech_center); next; # salta para proximo item do looping } } else { ## $msg_code = 11; ## regError($msg_code,$project_file_id,0,$tech_center,$dbm); } ($config{'DEBUG'} == 1 ? print "\nProject Name: $project_file_id e ID: $project_id\n" : ""); # ----------DESENHO----------#############------- # ---Verifica se desenho nao existe.--- ($config{'DEBUG'} == 1 ? print "\n\t\t\tDESENHO\n" : ""); $chk_a = 0; $sql = "select count(id) from cms_dfm where file_stat=1 and file_id='$desenho_file_id' and class_id='$desenho_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $chk_a = $db_parse_aux->fetchrow_array; if ($chk_a == 1) { # ---se existe desenho, link com project--- $desenho = "Existente"; $sql = "select id from cms_dfm where file_stat=1 and file_id='$desenho_file_id' and class_id='$desenho_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_id = $db_parse_aux->fetchrow_array; $sql = "select plc from cms_dfm where file_stat=1 and file_id='$desenho_file_id' and class_id='$desenho_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_plc = $db_parse_aux->fetchrow_array; $sql = "select status_code from cms_dfm where file_stat=1 and file_id='$desenho_file_id' and class_id='$desenho_class_id'"; $db_parse_aux = $dbo->prepare($sql) or die("Falha em SQL Prepare.\n"); $db_exec_aux = $db_parse_aux->execute or die("Falha em SQL Exec.\n"); $desenho_status_code = $db_parse_aux->fetchrow_array; if ($status_code_prc eq 'In Progress' and $desenho_status_code eq 'In Progress') { ($config{'DEBUG'} == 1 ? print "Criando Link entre $project_file_id and $desenho_file_id\n" : ""); $link = new ProductCenter::Link($cnxn,"Coupled"); $base = new ProductCenter::Item($cnxn, int $project_id); $child = new ProductCenter::Item($cnxn, int $desenho_id); $base->AddTailLink($link,$child); $base->Alter(); # $msg_code = 14; # regError($msg_code,desenho_file_id,$desenho_id,$tech_center,$dbm); } elsif ($status_code_prc eq 'Released' and $desenho_status_code eq 'In Progress') { $erro = 1; # Status code do desenho ou Pacote nao esta IP ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg3\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg3,14,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg3,14,$email,$tech_center); next; # salta para proximo item do looping } elsif ($status_code_prc eq 'In Approval' and $desenho_status_code eq 'In Approval') { # --IA x IA ($config{'DEBUG'} == 1 ? print "Verificando PDF\n" : ""); $base = new ProductCenter::Item($cnxn,int $desenho_id); $base->GetLinkCount("Coupled",$count); $pdf = 0; $plc = 0; for ($i = 0; $i < $count; $i++) { $link = $base->GetLink("Coupled",$i); $tail = $link->GetTail(); $pdf_name = $tail->GetAttr("FILE_ID"); $pdf_plc = $tail->GetAttr("PLC"); $aux = $project_file_id . '.pdf'; print "\n\t\t\tTail: " . $tail->GetAttr("FILE_ID") . "\n"; print "\n\t\t\tTail: " . $tail->GetAttr("PLC") . "\n"; if ($pdf_name eq $aux) { # encontrou PDF $pdf++; if ($pdf_plc eq $desenho_plc) { # encontrou PDF com plc igual do DRW $plc++; } } } if ($plc == 0) { $erro = 1; # Desenho inexistente ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg8\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg8,17,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg8,17,$email,$tech_center); next; # salta para proximo item do looping } } # --IA x IA } elsif ($pacote_file_title ne '') { $erro = 1; # Desenho inexistente ($config{'DEBUG'} == 1 ? print "Enviando Email para $originator: $msg6\n" : ""); # ---- sendEmail($dbm,$en_nbr,$msg6,10,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nbr,$msg6,10,$email,$tech_center); next; # salta para proximo item do looping } ($config{'DEBUG'} == 1 ? print "\nDrw Name: $desenho_file_id e ID: $desenho_id\n" : ""); # --- remove os projects que nao estao relacionados na GEN--- } # DEL } # --- looping interno--- # --- aprovacao do pacote --- ($config{'DEBUG'} == 1 ? print "\nVerificando necessidade de Aprovacao [$status_code_prc,$pacote_file_id,$saop,$pacote_id,$erro]\n" : ""); if ($status_code_prc eq 'Released') { ($config{'DEBUG'} == 1 ? print "\n\tDados de aprovacao: $pacote_status_code\n" : ""); if ($pacote_status_code eq 'In Approval' and $erro==5 and $saop ne 'SAOP') { # ---aprovar o pacote apenas nesta condicao--- ($config{'DEBUG'} == 1 ? print "\n\t\tAprovando $pacote_file_id [$saop]\n" : ""); $item_pacote1 = new ProductCenter::Item($cnxn,int $pacote_id); $item_pacote1->Approve("YES"); if ($cnxn->GetStatus() != SUCCESS) { ($config{'DEBUG'} == 1 ? print "\n\t\tFalha na Aprovacao de $pacote_file_id\n" : ""); # ---- sendEmail($dbm,$en_nb,$msg3,14,$originator,$tech_center); sendEmail($dbo,$dbm,$en_nb,$msg3,14,$email,$tech_center); } } } } # --- looping principal--- # --- ($config{'DEBUG'} == 1 ? print "\nDisconnecting $dbname database and ProductCenter..." : ""); $cnxn->Disconnect(); $dbo->disconnect(); ($config{'DEBUG'} == 1 ? print "disconnected.\n" : ""); exit(0);