diff --git a/.gitignore b/.gitignore index b5dc1b5..7cd25aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ pos_database.db ScannerGO/ScannerGO-* ScannerGO/config.json +DataToolsGO/imageTools-* diff --git a/DataToolsGO/build.sh b/DataToolsGO/build.sh new file mode 100755 index 0000000..482cf37 --- /dev/null +++ b/DataToolsGO/build.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Define binary names +LINUX_BIN="imageTools-linux" +LINUX_ARM_BIN="imageTools-linuxARMv7" +WINDOWS_BIN="imageTools-windows.exe" + +echo "Starting build process..." + +# Build for Linux (64-bit) +echo "Building for Linux..." +GOOS=linux GOARCH=amd64 go build -o "$LINUX_BIN" main.go + +if [ $? -eq 0 ]; then + echo "Successfully built: $LINUX_BIN" +else + echo "Failed to build Linux binary" + exit 1 +fi + +# Build for Windows (64-bit) +echo "Building for Windows..." +GOOS=windows GOARCH=amd64 go build -o "$WINDOWS_BIN" main.go + +if [ $? -eq 0 ]; then + echo "Successfully built: $WINDOWS_BIN" +else + echo "Failed to build Windows binary" + exit 1 +fi + +# Build for Linux ARM (ARMv7) +echo "Building for Linux ARMv7..." +GOOS=linux GOARCH=arm GOARM=7 go build -o "$LINUX_ARM_BIN" main.go +if [ $? -eq 0 ]; then + echo "Successfully built: $LINUX_ARM_BIN" +else + echo "Failed to build Linux ARMv7 binary" + exit 1 +fi + +echo "Build complete." diff --git a/DataToolsGO/go.mod b/DataToolsGO/go.mod new file mode 100644 index 0000000..1b8800a --- /dev/null +++ b/DataToolsGO/go.mod @@ -0,0 +1,5 @@ +module dataTools + +go 1.25.7 + +require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 diff --git a/DataToolsGO/go.sum b/DataToolsGO/go.sum new file mode 100644 index 0000000..96adbed --- /dev/null +++ b/DataToolsGO/go.sum @@ -0,0 +1,2 @@ +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= diff --git a/DataToolsGO/main.go b/DataToolsGO/main.go new file mode 100644 index 0000000..70b535b --- /dev/null +++ b/DataToolsGO/main.go @@ -0,0 +1,84 @@ +package main + +import ( + "flag" + "fmt" + "image" + "image/jpeg" + "os" + "path/filepath" + "strings" + + "github.com/nfnt/resize" +) + +func main() { + // Command line arguments + dirPath := flag.String("dir", "./", "Directory containing images") + maxWidth := flag.Uint("width", 1000, "Maximum width for resizing") + quality := flag.Int("quality", 75, "JPEG quality (1-100)") + flag.Parse() + + files, err := os.ReadDir(*dirPath) + if err != nil { + fmt.Printf("Error reading directory: %v\n", err) + return + } + + fmt.Printf("Processing images in %s (Max Width: %d, Quality: %d)\n", *dirPath, *maxWidth, *quality) + + for _, file := range files { + if file.IsDir() { + continue + } + + ext := strings.ToLower(filepath.Ext(file.Name())) + if ext != ".jpg" && ext != ".jpeg" && ext != ".png" { + continue + } + + filePath := filepath.Join(*dirPath, file.Name()) + processImage(filePath, *maxWidth, *quality) + } + + fmt.Println("Done. Your storage can finally breathe again.") +} + +func processImage(path string, maxWidth uint, quality int) { + file, err := os.Open(path) + if err != nil { + fmt.Printf("Failed to open %s: %v\n", path, err) + return + } + + img, _, err := image.Decode(file) + file.Close() + if err != nil { + fmt.Printf("Failed to decode %s: %v\n", path, err) + return + } + + // Only resize if original is wider than maxWidth + bounds := img.Bounds() + var finalImg image.Image + if uint(bounds.Dx()) > maxWidth { + finalImg = resize.Resize(maxWidth, 0, img, resize.Lanczos3) + fmt.Printf("Resized and compressed: %s\n", filepath.Base(path)) + } else { + finalImg = img + fmt.Printf("Compressed (no resize needed): %s\n", filepath.Base(path)) + } + + // Overwrite the original file + out, err := os.Create(path) + if err != nil { + fmt.Printf("Failed to create output file %s: %v\n", path, err) + return + } + defer out.Close() + + err = jpeg.Encode(out, finalImg, &jpeg.Options{Quality: quality}) + if err != nil { + fmt.Printf("Failed to encode %s: %v\n", path, err) + } +} diff --git a/app.py b/app.py index 7e40b23..863f794 100644 --- a/app.py +++ b/app.py @@ -112,7 +112,8 @@ def login(): @app.route('/logout') @login_required def logout(): - logout_user(); return redirect(url_for('login')) + logout_user() + return redirect(url_for('login')) @app.route('/') @login_required @@ -121,7 +122,13 @@ def index(): products = conn.execute('SELECT * FROM products').fetchall() return render_template('index.html', products=products, user=current_user) -@app.route('/upsert', methods=['POST']) +@app.route("/checkout") +@login_required +def checkout(): + return render_template("checkout.html", user=current_user) + + +@app.route("/upsert", methods=["POST"]) @login_required def upsert(): d = request.form @@ -161,10 +168,11 @@ def scan(): return jsonify({"status": "error", "message": "empty barcode"}), 400 with sqlite3.connect(DB_FILE) as conn: - p = conn.execute('SELECT * FROM products WHERE barcode = ?', (barcode,)).fetchone() + # Specifically select the 4 columns the code expects + p = conn.execute('SELECT barcode, name, price, image_url FROM products WHERE barcode = ?', (barcode,)).fetchone() - # 1. Product exists in local Database if p: + # Now this will always have exactly 4 values, regardless of DB changes barcode_val, name, price, image_path = p # Image recovery logic for missing local files @@ -266,8 +274,8 @@ def upload_image(): barcode = request.form['barcode'] if file.filename == '' or not barcode: return jsonify({"error": "Invalid data"}), 400 - ext = mimetypes.guess_extension(file.mimetype) or '.jpg' - filename = f"{barcode}{ext}" + + filename = f"{barcode}.jpg" filepath = os.path.join(CACHE_DIR, filename) file.save(filepath) timestamp = int(time.time()) diff --git a/templates/checkout.html b/templates/checkout.html new file mode 100644 index 0000000..2f755e0 --- /dev/null +++ b/templates/checkout.html @@ -0,0 +1,381 @@ + + + + + + + SekiPOS - Caja + + + + + + + + + + +
+
+
+
+

Carrito

+ + + + + + + + + + + + +
ProductoPrecio/UCant/PesoSubtotal
+
+
+ +
+
+

Último + Escaneado

+ product +
Esperando scan...
+ +
+ +
+
+

TOTAL

+

$0

+
+ + +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 810c8e2..501bffa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -261,7 +261,11 @@