OCR improvements: - Extract client data (name, CUI, address) from B2B receipts - Cross-validate amounts using payment methods and TVA entries - OCR-tolerant patterns for "TOTAL LEI" with common OCR errors - Better BON FISCAL vs CHITANTA detection Backend workflow fixes: - Fix SQLAlchemy deleted instance error in resubmit/submit workflow - Add session.refresh() after deleting accounting entries - Add unapprove endpoint (APPROVED → PENDING_REVIEW) - Add direction filter for receipt listing Frontend improvements: - Fix Vue v-else-if chain broken by Menu component - Unified OCR Preview layout with values table - Receipt list filter by direction (plati/incasari) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
372 lines
11 KiB
Bash
372 lines
11 KiB
Bash
#!/bin/bash
|
|
|
|
# Data Entry App - TEST Starter Script
|
|
# Oracle Server: 10.0.20.121 (via ssh-tunnel-test.sh)
|
|
# Database: receipts_test.db
|
|
# Schema test: MARIUSM_AUTO (company_id=110)
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m'
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
print_message() { echo -e "${CYAN}[DATA-ENTRY-TEST]${NC} $1"; }
|
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
|
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
check_port() {
|
|
local port=$1
|
|
lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1
|
|
}
|
|
|
|
# Individual service functions
|
|
stop_frontend() {
|
|
if check_port 3010; then
|
|
print_message "Stopping frontend..."
|
|
lsof -ti:3010 | xargs kill -TERM 2>/dev/null || true
|
|
sleep 1
|
|
lsof -ti:3010 | xargs kill -KILL 2>/dev/null || true
|
|
pkill -f "vite.*3010" 2>/dev/null || true
|
|
print_success "Frontend stopped"
|
|
else
|
|
print_warning "Frontend not running"
|
|
fi
|
|
}
|
|
|
|
stop_backend() {
|
|
if check_port 8003; then
|
|
print_message "Stopping backend..."
|
|
lsof -ti:8003 | xargs kill -TERM 2>/dev/null || true
|
|
sleep 1
|
|
lsof -ti:8003 | xargs kill -KILL 2>/dev/null || true
|
|
pkill -f "uvicorn.*8003" 2>/dev/null || true
|
|
print_success "Backend stopped"
|
|
else
|
|
print_warning "Backend not running"
|
|
fi
|
|
}
|
|
|
|
start_frontend() {
|
|
if check_port 3010; then
|
|
print_warning "Frontend already running on port 3010"
|
|
return 0
|
|
fi
|
|
|
|
print_message "Starting Frontend (Vue.js)..."
|
|
cd "$SCRIPT_DIR/data-entry-app/frontend/"
|
|
|
|
if [ ! -d "node_modules" ] || [ -f "node_modules/.bin/vite.cmd" ]; then
|
|
print_message "Installing frontend dependencies..."
|
|
rm -rf node_modules package-lock.json 2>/dev/null
|
|
npm install
|
|
fi
|
|
|
|
# Clear Vite cache for clean start
|
|
rm -rf node_modules/.vite 2>/dev/null || true
|
|
|
|
npm run dev -- --port 3010 > /tmp/data_entry_frontend.log 2>&1 &
|
|
|
|
for i in {1..15}; do
|
|
if check_port 3010; then
|
|
print_success "Frontend started on http://localhost:3010"
|
|
cd "$SCRIPT_DIR"
|
|
return 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
print_error "Frontend failed to start"
|
|
cat /tmp/data_entry_frontend.log
|
|
cd "$SCRIPT_DIR"
|
|
return 1
|
|
}
|
|
|
|
start_backend() {
|
|
if check_port 8003; then
|
|
print_warning "Backend already running on port 8003"
|
|
return 0
|
|
fi
|
|
|
|
print_message "Starting Backend (FastAPI)..."
|
|
cd "$SCRIPT_DIR/data-entry-app/backend/"
|
|
|
|
if [ ! -d "venv" ]; then
|
|
print_message "Creating virtual environment..."
|
|
python3 -m venv venv
|
|
fi
|
|
|
|
source venv/bin/activate
|
|
|
|
if ! python -c "import fastapi, uvicorn, sqlmodel" 2>/dev/null; then
|
|
print_message "Installing backend dependencies..."
|
|
pip install --upgrade pip > /dev/null 2>&1
|
|
pip install -r requirements.txt
|
|
fi
|
|
|
|
mkdir -p data/uploads
|
|
|
|
print_message "Running migrations..."
|
|
alembic upgrade head 2>/dev/null || print_warning "Migrations may already be applied"
|
|
|
|
uvicorn app.main:app --host 0.0.0.0 --port 8003 --reload > /tmp/data_entry_backend.log 2>&1 &
|
|
|
|
for i in {1..20}; do
|
|
if check_port 8003; then
|
|
print_success "Backend started on http://localhost:8003"
|
|
cd "$SCRIPT_DIR"
|
|
return 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
print_error "Backend failed to start"
|
|
cat /tmp/data_entry_backend.log
|
|
cd "$SCRIPT_DIR"
|
|
return 1
|
|
}
|
|
|
|
cleanup() {
|
|
print_message "Stopping services..."
|
|
stop_frontend
|
|
stop_backend
|
|
./ssh-tunnel-test.sh stop 2>/dev/null || true
|
|
print_success "All services stopped."
|
|
exit 0
|
|
}
|
|
|
|
stop_services() {
|
|
local target=${1:-all}
|
|
|
|
case $target in
|
|
frontend|fe|f)
|
|
stop_frontend
|
|
;;
|
|
backend|be|b)
|
|
stop_backend
|
|
;;
|
|
all|"")
|
|
print_message "Stopping all Data Entry TEST services..."
|
|
stop_frontend
|
|
stop_backend
|
|
./ssh-tunnel-test.sh stop 2>/dev/null || true
|
|
print_success "All Data Entry TEST services stopped!"
|
|
;;
|
|
*)
|
|
print_error "Unknown target: $target (use: frontend, backend, all)"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
start_services() {
|
|
local target=${1:-all}
|
|
|
|
case $target in
|
|
frontend|fe|f)
|
|
start_frontend
|
|
;;
|
|
backend|be|b)
|
|
# Ensure .env is correct
|
|
cp "$SCRIPT_DIR/data-entry-app/backend/.env.test" "$SCRIPT_DIR/data-entry-app/backend/.env" 2>/dev/null || true
|
|
start_backend
|
|
;;
|
|
all|"")
|
|
start_all
|
|
;;
|
|
*)
|
|
print_error "Unknown target: $target (use: frontend, backend, all)"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
restart_services() {
|
|
local target=${1:-all}
|
|
|
|
case $target in
|
|
frontend|fe|f)
|
|
stop_frontend
|
|
sleep 1
|
|
start_frontend
|
|
;;
|
|
backend|be|b)
|
|
stop_backend
|
|
sleep 1
|
|
start_backend
|
|
;;
|
|
all|"")
|
|
stop_services all
|
|
sleep 2
|
|
start_all
|
|
;;
|
|
*)
|
|
print_error "Unknown target: $target (use: frontend, backend, all)"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
show_status() {
|
|
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
|
echo -e "${CYAN} Data Entry App - TEST Status${NC}"
|
|
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
|
echo
|
|
|
|
if pgrep -f "ssh.*10.0.20.121" > /dev/null 2>&1 || ./ssh-tunnel-test.sh status 2>&1 | grep -q "10.0.20.121"; then
|
|
echo -e " SSH Tunnel: ${GREEN}✓ TEST (10.0.20.121)${NC}"
|
|
elif pgrep -f "ssh.*1526" > /dev/null 2>&1; then
|
|
echo -e " SSH Tunnel: ${YELLOW}⚠ Running (check which server)${NC}"
|
|
else
|
|
echo -e " SSH Tunnel: ${RED}✗ Stopped${NC}"
|
|
fi
|
|
|
|
if check_port 8003; then
|
|
echo -e " Backend: ${GREEN}✓ Running${NC} (http://localhost:8003)"
|
|
else
|
|
echo -e " Backend: ${RED}✗ Stopped${NC}"
|
|
fi
|
|
|
|
if check_port 3010; then
|
|
echo -e " Frontend: ${GREEN}✓ Running${NC} (http://localhost:3010)"
|
|
else
|
|
echo -e " Frontend: ${RED}✗ Stopped${NC}"
|
|
fi
|
|
|
|
echo
|
|
echo -e " Database: ${CYAN}receipts_test.db${NC}"
|
|
echo -e " Oracle: ${CYAN}10.0.20.121 (TEST)${NC}"
|
|
echo -e " Test Schema: ${CYAN}MARIUSM_AUTO (company_id=110)${NC}"
|
|
echo
|
|
}
|
|
|
|
show_usage() {
|
|
echo -e "${CYAN}Data Entry App - TEST Starter${NC}"
|
|
echo
|
|
echo "Usage:"
|
|
echo " ./start-data-entry-test.sh Start all services"
|
|
echo " ./start-data-entry-test.sh stop [target] Stop services"
|
|
echo " ./start-data-entry-test.sh start [target] Start services"
|
|
echo " ./start-data-entry-test.sh restart [target] Restart services"
|
|
echo " ./start-data-entry-test.sh status Show status"
|
|
echo
|
|
echo "Targets:"
|
|
echo " frontend, fe, f Frontend only (Vue.js on port 3010)"
|
|
echo " backend, be, b Backend only (FastAPI on port 8003)"
|
|
echo " all (default) All services"
|
|
echo
|
|
echo "Examples:"
|
|
echo " ./start-data-entry-test.sh restart frontend Restart only frontend"
|
|
echo " ./start-data-entry-test.sh stop backend Stop only backend"
|
|
echo " ./start-data-entry-test.sh start fe Start frontend (short)"
|
|
echo
|
|
echo "Environment:"
|
|
echo " Oracle Server: 10.0.20.121 (TEST)"
|
|
echo " SSH Tunnel: ./ssh-tunnel-test.sh"
|
|
echo " Config: .env.test"
|
|
echo " Database: receipts_test.db"
|
|
echo
|
|
}
|
|
|
|
start_all() {
|
|
trap cleanup SIGINT SIGTERM
|
|
|
|
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
|
echo -e "${CYAN} Data Entry App - TEST Environment${NC}"
|
|
echo -e "${CYAN} Oracle: 10.0.20.121 | DB: receipts_test.db${NC}"
|
|
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
|
echo
|
|
|
|
# Step 1: Stop any PRODUCTION tunnel and start TEST tunnel
|
|
print_message "1. Setting up SSH Tunnel (TEST)..."
|
|
./ssh_tunnel.sh stop 2>/dev/null || true
|
|
sleep 1
|
|
|
|
if ./ssh-tunnel-test.sh start; then
|
|
print_success "SSH Tunnel to TEST (10.0.20.121) started"
|
|
else
|
|
print_error "Failed to start SSH tunnel"
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
|
|
# Step 2: Copy TEST .env
|
|
print_message "2. Loading TEST environment..."
|
|
cp data-entry-app/backend/.env.test data-entry-app/backend/.env
|
|
print_success "Loaded .env.test (receipts_test.db)"
|
|
|
|
# Step 3: Start Frontend
|
|
print_message "3. Starting Frontend..."
|
|
start_frontend
|
|
|
|
# Step 4: Start Backend
|
|
print_message "4. Starting Backend..."
|
|
start_backend
|
|
|
|
# Summary
|
|
echo
|
|
echo -e "${GREEN}═══════════════════════════════════════════${NC}"
|
|
echo -e "${GREEN} Data Entry TEST Environment Ready!${NC}"
|
|
echo -e "${GREEN}═══════════════════════════════════════════${NC}"
|
|
echo
|
|
echo -e "${CYAN}Services:${NC}"
|
|
echo " • SSH Tunnel: 10.0.20.121 (TEST)"
|
|
echo " • Backend: http://localhost:8003"
|
|
echo " • Frontend: http://localhost:3010"
|
|
echo " • API Docs: http://localhost:8003/docs"
|
|
echo
|
|
echo -e "${CYAN}Database:${NC}"
|
|
echo " • SQLite: data/receipts_test.db"
|
|
echo " • Test Company: MARIUSM_AUTO (company_id=110)"
|
|
echo
|
|
echo -e "${YELLOW}Press Ctrl+C to stop all services${NC}"
|
|
echo
|
|
|
|
wait
|
|
}
|
|
|
|
# Parse arguments
|
|
case $1 in
|
|
stop)
|
|
stop_services "$2"
|
|
exit 0
|
|
;;
|
|
start)
|
|
if [ -z "$2" ] || [ "$2" = "all" ]; then
|
|
start_all
|
|
else
|
|
start_services "$2"
|
|
fi
|
|
exit 0
|
|
;;
|
|
restart)
|
|
restart_services "$2"
|
|
exit 0
|
|
;;
|
|
status)
|
|
show_status
|
|
exit 0
|
|
;;
|
|
help|--help|-h)
|
|
show_usage
|
|
exit 0
|
|
;;
|
|
"")
|
|
start_all
|
|
;;
|
|
*)
|
|
print_error "Unknown command: $1"
|
|
show_usage
|
|
exit 1
|
|
;;
|
|
esac
|