forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
13 KiB
256 lines
13 KiB
#!/bin/bash |
|
. /var/lib/asterisk/scripts/callcenter/bd |
|
|
|
TBL_AGENTES="pbx_supervisor_agentes" |
|
|
|
if [ -z "$1" -o -z "$2" ] |
|
then |
|
exit |
|
fi |
|
|
|
|
|
if [ "$1" = "CANALTRANSFER" ] |
|
then |
|
|
|
tipocanal=$(echo "$2" | cut -d "/" -f1) |
|
|
|
if [ "$tipocanal" = "Local" ] |
|
then |
|
ramal=$(echo "$2" | cut -d "/" -f2) |
|
else |
|
ramal=$(echo "$2" | cut -d "/" -f2 | cut -d "-" -f1) |
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET canal_transfer = '' WHERE ramal = '$ramal'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
if [ "$1" = "AGENTE-LOGOFF" ] |
|
then |
|
|
|
|
|
|
|
export PGPASSWORD=$SENHA |
|
STATUS=$(psql -Atc "select count(*) from $TBL_AGENTES where status in ('PAUSA','OCUPADO') and matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
if [ $STATUS = 0 ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "delete from $TBL_AGENTES where matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
echo "" >> /var/log/asterisk/atualizar-agente.log |
|
date +%d-%m-%Y-%H:%M:%S >> /var/log/asterisk/atualizar-agente.log |
|
echo "AGENTE = $2" >> /var/log/asterisk/atualizar-agente.log |
|
echo "STATUS = $3" >> /var/log/asterisk/atualizar-agente.log |
|
|
|
fi |
|
|
|
|
|
export PGPASSWORD=$SENHA |
|
MATRICULA=$(psql -Atc "select matricula from $TBL_AGENTES where ramal = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
export PGPASSWORD=$SENHA |
|
AUSENTE=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ -z $AUSENTE ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "insert into pbx_motivos_pausas (motivo) values ('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
export PGPASSWORD=$SENHA |
|
AUSENTE=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
#ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select max(matricula),max(ramal),max(id_dac),'$AUSENTE',now(),'0',max(relaciona_eventos),now() from pbx_eventos_agentes where matricula = '$MATRICULA' and login is not null) ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$AUSENTE',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$MATRICULA') ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '',motivo_pausa = 'ausente', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$MATRICULA'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
|
|
fi |
|
|
|
if [ "$1" = "ESCUTA-CLASSIFICACAO" ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET canal_agente = '$3' WHERE ramal = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
if [ "$1" = "PAUSA-AUSENTE" ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
MATRICULA=$(psql -Atc "select matricula from $TBL_AGENTES where ramal = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
export PGPASSWORD=$SENHA |
|
AUSENTE=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ -z $AUSENTE ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "insert into pbx_motivos_pausas (motivo) values ('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
export PGPASSWORD=$SENHA |
|
AUSENTE=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('ausente')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
#ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select max(matricula),max(ramal),max(id_dac),'$AUSENTE',now(),'0',max(relaciona_eventos),now() from pbx_eventos_agentes where matricula = '$MATRICULA' and login is not null) ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$AUSENTE',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$MATRICULA') ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',protocolo = '', duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '', tipo_discagem = '',motivo_pausa = 'ausente', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$MATRICULA'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
|
|
fi |
|
|
|
|
|
if [ "$1" = "RAMAL" ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
#PAUSA=$(psql -Atc "select count(*) from $TBL_AGENTES where status in ('PAUSA','OCUPADO') and ramal = '$3'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
PAUSA=$(psql -Atc "select count(*) from $TBL_AGENTES where status in ('PAUSA') and ramal = '$3'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
echo 'Pausa = '$PAUSA |
|
if [ $PAUSA = 0 ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = '$2' , duracao = 'now()' , origem_destino = '',canal = '' , sala_1 = '' , sala_2 = '' , facilidade = '' , canal_agente = '' , canal_transfer = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '', protocolo = '' WHERE ramal = '$3'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
fi |
|
|
|
if [ "$1" = "GRAVACAO" ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status_gravacao = 'V' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
|
|
if [ "$1" = "CAMPANHA" ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
FILA_DAC=$(psql -Atc "select dac from pbx_supervisor_agentes where matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
VERIFICA_FILA=$(psql -Atc "select a.id, count(*) as dac, (select count(*) from pbx_pausa_automatica where iddac = a.id) as pausa_automatica from pbx_queues_grupos a where nome = '$FILA_DAC' group by a.id" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
ID=$(echo "$VERIFICA_FILA" | cut -d "|" -f1) |
|
DAC=$(echo "$VERIFICA_FILA" | cut -d "|" -f2) |
|
PAUSA_AUTO=$(echo "$VERIFICA_FILA" | cut -d "|" -f3) |
|
|
|
if ! [ -z $ID ] |
|
then |
|
|
|
if [ "$PAUSA_AUTO" = "1" ] |
|
then |
|
|
|
export PGPASSWORD=$SENHA |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ -z $ACW ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "insert into pbx_motivos_pausas (motivo) values ('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
export PGPASSWORD=$SENHA |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
fi |
|
|
|
|
|
|
|
export PGPASSWORD=$SENHA |
|
ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select max(matricula),max(ramal),max(id_dac),'$ACW',now(),'0',max(relaciona_eventos),now() from pbx_eventos_agentes where matricula = '$2' and login is not null) ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '',motivo_pausa = 'acw', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'LIVRE',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '', protocolo = '' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
|
|
|
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ -z $ACW ] |
|
then |
|
|
|
psql -c "insert into pbx_motivos_pausas (motivo) values ('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
fi |
|
|
|
|
|
DADOS=$(psql -Atc "select ramal,dac,relaciona_evento from pbx_supervisor_agentes where matricula = '$2' limit 1" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
echo "$DADOS" |
|
echo "$DADOS" | while read LINHA; do |
|
RAMAL=$(echo "$LINHA" | cut -d "|" -f1) |
|
DAC=$(echo "$LINHA" | cut -d "|" -f2) |
|
RELACIONA_EVENTOS=$(echo "$LINHA" | cut -d "|" -f3) |
|
|
|
|
|
export PGPASSWORD=$SENHA |
|
ID_DAC=$(psql -Atc "select cmp_id from pbx_campanha where cmp_descricao = '$DAC' " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) values ('$2','$RAMAL','$ID_DAC','$ACW','now()','0','$RELACIONA_EVENTOS','now()') ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '',motivo_pausa = 'acw', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
done |
|
|
|
exit |
|
fi |
|
|
|
if [ "$1" = "LOGIN" ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',tipo_discagem = '',motivo_pausa = 'login' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
exit |
|
fi |
|
|
|
#FILA="$3" |
|
export PGPASSWORD=$SENHA |
|
FILA=$(psql -Atc "select dac from pbx_supervisor_agentes where matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
export PGPASSWORD=$SENHA |
|
AUTOPAUSA=$(psql -Atc "select count(*) from pbx_pausa_automatica where iddac = (select id from pbx_queues_grupos where nome = '$FILA') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ "$AUTOPAUSA" = "1" ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
if [ -z $ACW ] |
|
then |
|
export PGPASSWORD=$SENHA |
|
psql -c "insert into pbx_motivos_pausas (motivo) values ('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
export PGPASSWORD=$SENHA |
|
ACW=$(psql -Atc "select id from pbx_motivos_pausas where upper(motivo) = upper('acw')" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
fi |
|
|
|
|
|
|
|
export PGPASSWORD=$SENHA |
|
ID_EVENTOS_AGENTE=$(psql -Atc "insert into pbx_eventos_agentes (matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos, saida_pausa) (select a.matricula, a.ramal, b.id as id_dac,'$ACW',now(),'0', '0',now() from pbx_supervisor_agentes a, pbx_dacs b where b.nome = a.dac and a.matricula = '$2') ; select currval('pbx_eventos_agentes_id_seq') " -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
export PGPASSWORD=$SENHA |
|
psql -c "UPDATE $TBL_AGENTES SET status = 'PAUSA',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '',tipo_discagem = '',motivo_pausa = 'acw', id_eventos_agente = '$ID_EVENTOS_AGENTE' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
export PGPASSWORD=$SENHA |
|
PAUSA=$(psql -Atc "select count(*) from $TBL_AGENTES where status = 'PAUSA' and matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO) |
|
|
|
echo 'Pausa = '$PAUSA |
|
if [ $PAUSA = 1 ] |
|
then |
|
psql -c "UPDATE $TBL_AGENTES SET origem_destino = '',tipo_ligacao = '',status_gravacao = 'F', protocolo = '', uniqueid = '',canal = '',canal_agente = '',canal_transfer = '' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
exit |
|
fi |
|
|
|
psql -c "UPDATE $TBL_AGENTES SET status = '$1',duracao = now(),origem_destino = '',tipo_ligacao = '',status_gravacao = 'F',uniqueid = '',canal = '',canal_agente = '',canal_transfer = '',tipo_discagem = '', protocolo = '' WHERE matricula = '$2'" -h $HOST_DB -d $BASE_DB -U $USUARIO |
|
|
|
|
|
|