#!/bin/bash

#
# This script was made to create an integration between the POS and
# Miravision. The ideia is to create a system where multiple POS call
# a single queue of persons (like Primark)
#

CLERK=$1
STATION=$2
AREA=$3
CHECK=$4

#MIRA_IP="192.168.1.18"
MIRA_IP=""

if [ "$MIRA_IP" = "" ]; then
  xmessage -center -timeout 5 "Edit common/data/custom_scripts/miravision_terminal_caller and define MIRA_IP"
  echo "STOP"
  exit
fi

export DISPLAY=:0.0

#xmessage "ALERT MESSAGE! CLERK: $CLERK, STATION: $STATION, AREA: $AREA, CHECK: $CHECK"

STATION_NAME=`cat /opt/pos/etc/config.ini | grep STATION_NAME | cut -f2 -d=`

if [ "$STATION_NAME" = "" ]; then
  STATION_NAME=`expr $STATION + 1`
fi

wget -O /tmp/filas_info.txt http://$MIRA_IP:3001/filas/info
TNUMBER=`cat /tmp/filas_info.txt | grep tnumber | cut -f2 -d: | cut -f2 -d"\""`

if [ "$TNUMBER" != "" ]; then
  if [ "$TNUMBER" != "$STATION_NAME" ]; then
    wget -O /dev/null http://$MIRA_IP:3001/filas_anterior/tset/B/$TNUMBER
  fi
fi

wget -O /dev/null "http://$MIRA_IP:3001/filas/tset/A/$STATION_NAME"
#wget -O /dev/null http://$MIRA_IP:3001/blink
wget -O /dev/null "http://$MIRA_IP:3001/beep"

echo "STOP"

