Преглед изворни кода

Organizacion de archivos para impresion

David Gómez пре 1 месец
родитељ
комит
6e6b87f1ee

+ 1 - 1
comanda.php → print_caja/comanda.php

@@ -16,7 +16,7 @@ ini_set('display_errors', 0);
 ini_set('log_errors', 1);
 ini_set('error_log', 'logs/error.log');
 
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 use Mike42\Escpos\Printer;
 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
 use Mike42\Escpos\EscposImage;

+ 34 - 7
corte.php → print_caja/corte_caja.php

@@ -16,7 +16,7 @@ ini_set('display_errors', 0);
 ini_set('log_errors', 1);
 ini_set('error_log', '/logs/error.log');
 
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 use Mike42\Escpos\Printer;
 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
 use Mike42\Escpos\EscposImage;
@@ -72,8 +72,10 @@ if ($dataPrint) {
     $dotacion = $dataPrint['dotacion'] ?? 0;
     $dataCorteFiscal = $dataPrint['dataCorteFiscal'] ?? [];
     
-    // Log de dataCorteFiscal
+    // Log de dataCorteFiscal y dotacion
     error_log("dataCorteFiscal: " . print_r($dataCorteFiscal, true));
+    error_log("Dotacion recibida en corte.php: " . $dotacion);
+    error_log("Dotacion en dataCorteFiscal['dotacion']: " . (isset($dataCorteFiscal['dotacion']) ? $dataCorteFiscal['dotacion'] : 'NO EXISTE'));
 }
 
 if ($printCorteFiscal && !empty($dataCorteFiscal)) {
@@ -210,15 +212,40 @@ if ($printCorteFiscal && !empty($dataCorteFiscal)) {
         printSeparatorLine($printer);
         
         // DOTACION
-        printAlignedText($printer, "Dotacion:", "$" . number_format($dotacion, 2));
+        printSeparatorLine($printer, "=");
+        $printer->setEmphasis(true);
+        $printer->text("CALCULO EFECTIVO EN CAJA:\n");
+        $printer->setEmphasis(false);
         printSeparatorLine($printer);
         
         // TOTAL EFECTIVO CAJA
-        $total_efectivo_caja = $dotacion + ($dataCorteFiscal['total_ventas_efectivo'] ?? 0) + 
-                              ($dataCorteFiscal['total_ventas_efectivo_cc'] ?? 0) - $total_egresos_cc + $total_ingresos_cc;
-        printAlignedText($printer, "Total Efectivo Caja:", "$" . number_format($total_efectivo_caja, 2));
+        $total_ventas_efectivo_val = $dataCorteFiscal['total_ventas_efectivo'] ?? 0;
+        $total_ventas_efectivo_cc_val = $dataCorteFiscal['total_ventas_efectivo_cc'] ?? 0;
+        
+        printAlignedText($printer, "Dotacion:", "$" . number_format($dotacion, 2));
+        printAlignedText($printer, "+ Ventas Efectivo:", "$" . number_format($total_ventas_efectivo_val, 2));
+        if ($total_ventas_efectivo_cc_val > 0) {
+            printAlignedText($printer, "+ Ventas Efectivo CC:", "$" . number_format($total_ventas_efectivo_cc_val, 2));
+        }
+        if ($total_ingresos_cc > 0) {
+            printAlignedText($printer, "+ Ingresos Caja Chica:", "$" . number_format($total_ingresos_cc, 2));
+        }
+        if ($total_egresos_cc > 0) {
+            printAlignedText($printer, "- Egresos Caja Chica:", "($" . number_format($total_egresos_cc, 2) . ")");
+        }
+        printSeparatorLine($printer, "=");
+        
+        $total_efectivo_caja = $dotacion + $total_ventas_efectivo_val + $total_ventas_efectivo_cc_val - $total_egresos_cc + $total_ingresos_cc;
+        
+        $printer->setEmphasis(true);
+        $printer->setTextSize(2, 1);
+        printAlignedText($printer, "TOTAL CAJA:", "$" . number_format($total_efectivo_caja, 2));
+        $printer->setTextSize(1, 1);
+        $printer->setEmphasis(false);
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
         $printer->text("(Efectivo + Dotacion +- Caja Chica)\n");
-        printSeparatorLine($printer);
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        printSeparatorLine($printer, "=");
         
         // CAJERO Y FECHA
         $printer->text("Cajero: " . $cajero . "\n");

+ 2 - 1
precuenta.php → print_caja/precuenta_caja.php

@@ -24,7 +24,7 @@ ini_set('display_errors', 0);
 ini_set('log_errors', 1);
 ini_set('error_log', __DIR__ . '/logs/error.log');
 
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 use Mike42\Escpos\Printer;
 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
 
@@ -57,6 +57,7 @@ try {
     $printer->setTextSize(2, 2);
     $printer->text($dataPrint['nombre_empresa'] . "\n");
     $printer->setTextSize(1, 1);
+    $printer->text($dataPrint['direccion_empresa'] . "\n");
     $printer->text(str_repeat("=", 45) . "\n");
     $printer->setEmphasis(true);
     $printer->text("PRECUENTA\n");

+ 250 - 0
print_express/comanda.php

@@ -0,0 +1,250 @@
+<?php
+if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+    header("Access-Control-Allow-Origin: *");
+    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
+    http_response_code(204);
+    exit;
+}
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
+header("Access-Control-Allow-Headers: Content-Type, Authorization");
+
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('log_errors', 1);
+ini_set('error_log', 'logs/error.log');
+
+require __DIR__ . '/../vendor/autoload.php';
+use Mike42\Escpos\Printer;
+use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
+use Mike42\Escpos\EscposImage;
+
+// Recibir datos - puede venir como JSON string o como objeto serializado por jQuery
+$dataComanda = null;
+
+if(isset($_POST["dataComanda"])){
+    if(is_string($_POST["dataComanda"])){
+        $dataComanda = json_decode($_POST["dataComanda"]);
+    } else {
+        $dataComanda = json_decode(json_encode($_POST["dataComanda"]));
+    }
+} elseif(isset($_POST["dataPrint"])){
+    if(is_string($_POST["dataPrint"])){
+        $dataComanda = json_decode($_POST["dataPrint"]);
+    } else {
+        $dataComanda = json_decode(json_encode($_POST["dataPrint"]));
+    }
+}
+
+if($dataComanda){
+    // Verificar si tiene productos_cocina ya generados
+    if(isset($dataComanda->productos_cocina) && is_array($dataComanda->productos_cocina) && count($dataComanda->productos_cocina) > 0){
+        $productosPorCocina = $dataComanda->productos_cocina;
+    } else {
+        // Si no tiene productos_cocina, retornar error silencioso (no hay nada que imprimir en cocina)
+        echo json_encode(array('status' => 'success', 'message' => 'No hay productos para cocina'));
+        exit;
+    }
+    
+    // Datos generales
+    $fecha = $dataComanda->fecha ?? date("d-m-Y H:i:s");
+    $numeroOrden = $dataComanda->numero_orden ?? ($dataComanda->referencia ?? "N/A");
+    
+    // Extraer número de orden si viene con formato V-, C-, D-
+    if(isset($numeroOrden) && is_string($numeroOrden)){
+        $numeroOrden = str_replace(array("V-", "C-", "D-"), "", $numeroOrden);
+    }
+    
+    $mesa = $dataComanda->mesa_orden ?? ($dataComanda->mesa ?? "N/A");
+    $mesero = $dataComanda->mesero ?? ($dataComanda->vendedor ?? "");
+    $cliente = $dataComanda->cliente ?? "";
+    $servicio = $dataComanda->servicio ?? "";
+    $notas = $dataComanda->notas ?? "";
+    $observaciones = $dataComanda->observaciones ?? "";
+    
+    $resultados = [];
+    
+    // Imprimir una comanda por cada cocina
+    foreach ($productosPorCocina as $cocina) {
+        try {
+            $PRINTER_NAME = $cocina->impresor;
+            $anchoPapel = intval($cocina->ancho_papel ?? 80);
+            $maxCaracteres = ($anchoPapel == 80) ? 45 : 32; // Caracteres según ancho de papel
+            $maxDescripcion = ($anchoPapel == 80) ? 28 : 20;
+            
+            $connector = new WindowsPrintConnector($PRINTER_NAME);
+            $printer = new Printer($connector);
+            
+            // ENCABEZADO
+            $printer->setJustification(Printer::JUSTIFY_CENTER);
+            $printer->setTextSize(2, 2);
+            $printer->text("COMANDA\n");
+            $printer->setTextSize(1, 1);
+            $printer->text(strtoupper($cocina->nombre_cocina) . "\n");
+            $printer->text(str_repeat("=", $maxCaracteres) . "\n");
+            
+            // INFORMACIÓN DE LA ORDEN
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->setEmphasis(true);
+            $printer->text("Fecha: ");
+            $printer->setEmphasis(false);
+            $printer->text("$fecha\n");
+            
+            $printer->setEmphasis(true);
+            $printer->text("Orden: ");
+            $printer->setEmphasis(false);
+            $printer->text("$numeroOrden");
+            
+            $printer->setEmphasis(true);
+            $printer->text("  Mesa: ");
+            $printer->setEmphasis(false);
+            $printer->text("$mesa\n");
+            
+            if($mesero && $mesero != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Mesero: ");
+                $printer->setEmphasis(false);
+                $printer->text("$mesero\n");
+            }
+            
+            if($cliente && $cliente != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Cliente: ");
+                $printer->setEmphasis(false);
+                $printer->text("$cliente\n");
+            }
+            
+            if($servicio && $servicio != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Servicio: ");
+                $printer->setEmphasis(false);
+                $printer->text("$servicio\n");
+            }
+            
+            $printer->text(str_repeat("-", $maxCaracteres) . "\n");
+            
+            // PRODUCTOS
+            $printer->setEmphasis(true);
+            $printer->setTextSize(1, 1);
+            $printer->text("Cant  Descripcion\n");
+            $printer->setEmphasis(false);
+            $printer->text(str_repeat("-", $maxCaracteres) . "\n");
+            
+            foreach ($cocina->productos as $producto) {
+                // Formatear cantidad
+                $cantidad = str_pad(number_format($producto->cant, 2), 6, " ", STR_PAD_RIGHT);
+                
+                // Descripción del producto
+                $descripcion = $producto->desc;
+                $descripcionLineas = explode("\n", wordwrap($descripcion, $maxDescripcion, "\n", true));
+                
+                // Primera línea con cantidad
+                $printer->setTextSize(1, 1);
+                $printer->text("$cantidad " . $descripcionLineas[0] . "\n");
+                
+                // Líneas adicionales de descripción
+                for ($i = 1; $i < count($descripcionLineas); $i++) {
+                    $printer->text("      " . $descripcionLineas[$i] . "\n");
+                }
+                
+                // Acompañamientos si existen
+                if (isset($producto->acompanamientos) && $producto->acompanamientos != "") {
+                    $printer->setEmphasis(true);
+                    $printer->text("      CON: ");
+                    $printer->setEmphasis(false);
+                    $printer->text($producto->acompanamientos . "\n");
+                }
+
+                // Notas del producto si existen
+                if (isset($producto->notas) && $producto->notas != "") {
+                    $printer->setEmphasis(true);
+                    $printer->text("      NOTA: ");
+                    $printer->setEmphasis(false);
+                    $notasLineas = explode("\n", wordwrap($producto->notas, $maxDescripcion - 6, "\n", true));
+                    $printer->text($notasLineas[0] . "\n");
+                    for ($j = 1; $j < count($notasLineas); $j++) {
+                        $printer->text("            " . $notasLineas[$j] . "\n");
+                    }
+                }
+                
+                $printer->text("\n");
+            }
+            
+            $printer->text(str_repeat("=", $maxCaracteres) . "\n");
+            
+            // NOTAS GENERALES
+            if($notas && $notas != ""){
+                $printer->setEmphasis(true);
+                $printer->text("NOTAS:\n");
+                $printer->setEmphasis(false);
+                $notasLineas = explode("\n", wordwrap($notas, $maxCaracteres, "\n", true));
+                foreach($notasLineas as $linea){
+                    $printer->text($linea . "\n");
+                }
+                $printer->text("\n");
+            }
+            
+            if($observaciones && $observaciones != ""){
+                $printer->setEmphasis(true);
+                $printer->text("OBSERVACIONES:\n");
+                $printer->setEmphasis(false);
+                $obsLineas = explode("\n", wordwrap($observaciones, $maxCaracteres, "\n", true));
+                foreach($obsLineas as $linea){
+                    $printer->text($linea . "\n");
+                }
+                $printer->text("\n");
+            }
+            
+            // PIE
+            $printer->setJustification(Printer::JUSTIFY_CENTER);
+            $printer->setTextSize(2, 2);
+            $printer->text("PREPARAR\n");
+            $printer->setTextSize(1, 1);
+            $printer->text("Orden: $numeroOrden\n");
+            
+            // CORTAR PAPEL Y CERRAR IMPRESORA
+            $printer->feed(3);
+            $printer->cut();
+            $printer->close();
+            
+            $resultados[] = [
+                "cocina" => $cocina->nombre_cocina,
+                "impresora" => $PRINTER_NAME,
+                "status" => "success",
+                "message" => "Comanda impresa correctamente"
+            ];
+            
+        } catch (Exception $e) {
+            $resultados[] = [
+                "cocina" => $cocina->nombre_cocina ?? "Desconocida",
+                "impresora" => $PRINTER_NAME ?? "Desconocida",
+                "status" => "error",
+                "message" => "Error al imprimir: " . $e->getMessage()
+            ];
+        }
+    }
+    
+    // Verificar si todas las impresiones fueron exitosas
+    $todosExitosos = true;
+    foreach($resultados as $resultado){
+        if($resultado["status"] != "success"){
+            $todosExitosos = false;
+            break;
+        }
+    }
+    
+    echo json_encode([
+        "status" => $todosExitosos ? "success" : "partial",
+        "message" => $todosExitosos ? "Todas las comandas impresas correctamente" : "Algunas comandas no se pudieron imprimir",
+        "resultados" => $resultados
+    ]);
+    
+} else {
+    echo json_encode([
+        "status" => "error",
+        "message" => "No se recibieron datos para imprimir comandas."
+    ]);
+}
+?>

+ 250 - 0
print_express/comanda_express.php

@@ -0,0 +1,250 @@
+<?php
+if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+    header("Access-Control-Allow-Origin: *");
+    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
+    http_response_code(204);
+    exit;
+}
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
+header("Access-Control-Allow-Headers: Content-Type, Authorization");
+
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('log_errors', 1);
+ini_set('error_log', 'logs/error.log');
+
+require __DIR__ . '/../vendor/autoload.php';
+use Mike42\Escpos\Printer;
+use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
+use Mike42\Escpos\EscposImage;
+
+// Recibir datos - puede venir como JSON string o como objeto serializado por jQuery
+$dataComanda = null;
+
+if(isset($_POST["dataComanda"])){
+    if(is_string($_POST["dataComanda"])){
+        $dataComanda = json_decode($_POST["dataComanda"]);
+    } else {
+        $dataComanda = json_decode(json_encode($_POST["dataComanda"]));
+    }
+} elseif(isset($_POST["dataPrint"])){
+    if(is_string($_POST["dataPrint"])){
+        $dataComanda = json_decode($_POST["dataPrint"]);
+    } else {
+        $dataComanda = json_decode(json_encode($_POST["dataPrint"]));
+    }
+}
+
+if($dataComanda){
+    // Verificar si tiene productos_cocina ya generados
+    if(isset($dataComanda->productos_cocina) && is_array($dataComanda->productos_cocina) && count($dataComanda->productos_cocina) > 0){
+        $productosPorCocina = $dataComanda->productos_cocina;
+    } else {
+        // Si no tiene productos_cocina, retornar error silencioso (no hay nada que imprimir en cocina)
+        echo json_encode(array('status' => 'success', 'message' => 'No hay productos para cocina'));
+        exit;
+    }
+    
+    // Datos generales
+    $fecha = $dataComanda->fecha ?? date("d-m-Y H:i:s");
+    $numeroOrden = $dataComanda->numero_orden ?? ($dataComanda->referencia ?? "N/A");
+    
+    // Extraer número de orden si viene con formato V-, C-, D-
+    if(isset($numeroOrden) && is_string($numeroOrden)){
+        $numeroOrden = str_replace(array("V-", "C-", "D-"), "", $numeroOrden);
+    }
+    
+    $mesa = $dataComanda->mesa_orden ?? ($dataComanda->mesa ?? "N/A");
+    $mesero = $dataComanda->mesero ?? ($dataComanda->vendedor ?? "");
+    $cliente = $dataComanda->cliente ?? "";
+    $servicio = $dataComanda->servicio ?? "";
+    $notas = $dataComanda->notas ?? "";
+    $observaciones = $dataComanda->observaciones ?? "";
+    
+    $resultados = [];
+    
+    // Imprimir una comanda por cada cocina
+    foreach ($productosPorCocina as $cocina) {
+        try {
+            $PRINTER_NAME = $cocina->impresor;
+            $anchoPapel = intval($cocina->ancho_papel ?? 80);
+            $maxCaracteres = ($anchoPapel == 80) ? 45 : 32; // Caracteres según ancho de papel
+            $maxDescripcion = ($anchoPapel == 80) ? 28 : 20;
+            
+            $connector = new WindowsPrintConnector($PRINTER_NAME);
+            $printer = new Printer($connector);
+            
+            // ENCABEZADO
+            $printer->setJustification(Printer::JUSTIFY_CENTER);
+            $printer->setTextSize(2, 2);
+            $printer->text("COMANDA\n");
+            $printer->setTextSize(1, 1);
+            $printer->text(strtoupper($cocina->nombre_cocina) . "\n");
+            $printer->text(str_repeat("=", $maxCaracteres) . "\n");
+            
+            // INFORMACIÓN DE LA ORDEN
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->setEmphasis(true);
+            $printer->text("Fecha: ");
+            $printer->setEmphasis(false);
+            $printer->text("$fecha\n");
+            
+            $printer->setEmphasis(true);
+            $printer->text("Orden: ");
+            $printer->setEmphasis(false);
+            $printer->text("$numeroOrden");
+            
+            $printer->setEmphasis(true);
+            $printer->text("  Mesa: ");
+            $printer->setEmphasis(false);
+            $printer->text("$mesa\n");
+            
+            if($mesero && $mesero != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Mesero: ");
+                $printer->setEmphasis(false);
+                $printer->text("$mesero\n");
+            }
+            
+            if($cliente && $cliente != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Cliente: ");
+                $printer->setEmphasis(false);
+                $printer->text("$cliente\n");
+            }
+            
+            if($servicio && $servicio != ""){
+                $printer->setEmphasis(true);
+                $printer->text("Servicio: ");
+                $printer->setEmphasis(false);
+                $printer->text("$servicio\n");
+            }
+            
+            $printer->text(str_repeat("-", $maxCaracteres) . "\n");
+            
+            // PRODUCTOS
+            $printer->setEmphasis(true);
+            $printer->setTextSize(1, 1);
+            $printer->text("Cant  Descripcion\n");
+            $printer->setEmphasis(false);
+            $printer->text(str_repeat("-", $maxCaracteres) . "\n");
+            
+            foreach ($cocina->productos as $producto) {
+                // Formatear cantidad
+                $cantidad = str_pad(number_format($producto->cant, 2), 6, " ", STR_PAD_RIGHT);
+                
+                // Descripción del producto
+                $descripcion = $producto->desc;
+                $descripcionLineas = explode("\n", wordwrap($descripcion, $maxDescripcion, "\n", true));
+                
+                // Primera línea con cantidad
+                $printer->setTextSize(1, 1);
+                $printer->text("$cantidad " . $descripcionLineas[0] . "\n");
+                
+                // Líneas adicionales de descripción
+                for ($i = 1; $i < count($descripcionLineas); $i++) {
+                    $printer->text("      " . $descripcionLineas[$i] . "\n");
+                }
+                
+                // Acompañamientos si existen
+                if (isset($producto->acompanamientos) && $producto->acompanamientos != "") {
+                    $printer->setEmphasis(true);
+                    $printer->text("      CON: ");
+                    $printer->setEmphasis(false);
+                    $printer->text($producto->acompanamientos . "\n");
+                }
+
+                // Notas del producto si existen
+                if (isset($producto->notas) && $producto->notas != "") {
+                    $printer->setEmphasis(true);
+                    $printer->text("      NOTA: ");
+                    $printer->setEmphasis(false);
+                    $notasLineas = explode("\n", wordwrap($producto->notas, $maxDescripcion - 6, "\n", true));
+                    $printer->text($notasLineas[0] . "\n");
+                    for ($j = 1; $j < count($notasLineas); $j++) {
+                        $printer->text("            " . $notasLineas[$j] . "\n");
+                    }
+                }
+                
+                $printer->text("\n");
+            }
+            
+            $printer->text(str_repeat("=", $maxCaracteres) . "\n");
+            
+            // NOTAS GENERALES
+            if($notas && $notas != ""){
+                $printer->setEmphasis(true);
+                $printer->text("NOTAS:\n");
+                $printer->setEmphasis(false);
+                $notasLineas = explode("\n", wordwrap($notas, $maxCaracteres, "\n", true));
+                foreach($notasLineas as $linea){
+                    $printer->text($linea . "\n");
+                }
+                $printer->text("\n");
+            }
+            
+            if($observaciones && $observaciones != ""){
+                $printer->setEmphasis(true);
+                $printer->text("OBSERVACIONES:\n");
+                $printer->setEmphasis(false);
+                $obsLineas = explode("\n", wordwrap($observaciones, $maxCaracteres, "\n", true));
+                foreach($obsLineas as $linea){
+                    $printer->text($linea . "\n");
+                }
+                $printer->text("\n");
+            }
+            
+            // PIE
+            $printer->setJustification(Printer::JUSTIFY_CENTER);
+            $printer->setTextSize(2, 2);
+            $printer->text("PREPARAR\n");
+            $printer->setTextSize(1, 1);
+            $printer->text("Orden: $numeroOrden\n");
+            
+            // CORTAR PAPEL Y CERRAR IMPRESORA
+            $printer->feed(3);
+            $printer->cut();
+            $printer->close();
+            
+            $resultados[] = [
+                "cocina" => $cocina->nombre_cocina,
+                "impresora" => $PRINTER_NAME,
+                "status" => "success",
+                "message" => "Comanda impresa correctamente"
+            ];
+            
+        } catch (Exception $e) {
+            $resultados[] = [
+                "cocina" => $cocina->nombre_cocina ?? "Desconocida",
+                "impresora" => $PRINTER_NAME ?? "Desconocida",
+                "status" => "error",
+                "message" => "Error al imprimir: " . $e->getMessage()
+            ];
+        }
+    }
+    
+    // Verificar si todas las impresiones fueron exitosas
+    $todosExitosos = true;
+    foreach($resultados as $resultado){
+        if($resultado["status"] != "success"){
+            $todosExitosos = false;
+            break;
+        }
+    }
+    
+    echo json_encode([
+        "status" => $todosExitosos ? "success" : "partial",
+        "message" => $todosExitosos ? "Todas las comandas impresas correctamente" : "Algunas comandas no se pudieron imprimir",
+        "resultados" => $resultados
+    ]);
+    
+} else {
+    echo json_encode([
+        "status" => "error",
+        "message" => "No se recibieron datos para imprimir comandas."
+    ]);
+}
+?>

+ 237 - 0
print_express/precuenta.php

@@ -0,0 +1,237 @@
+<?php
+if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+    header("Access-Control-Allow-Origin: *");
+    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
+    http_response_code(204);
+    exit;
+}
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
+header("Access-Control-Allow-Headers: Content-Type, Authorization");
+
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('log_errors', 1);
+ini_set('error_log', __DIR__ . '/logs/error.log');
+
+require __DIR__ . '/../vendor/autoload.php';
+use Mike42\Escpos\Printer;
+use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
+
+// Helper functions
+function printLinea($printer, $char = "-", $width = 48) {
+    $printer->text(str_repeat($char, $width) . "\n");
+}
+
+function cutString($text, $maxLength) {
+    return substr($text, 0, $maxLength);
+}
+
+function printAlignedText($printer, $leftText, $rightText, $width = 48) {
+    $rightLen = strlen($rightText);
+    $leftLen = $width - $rightLen;
+    $leftPadded = str_pad($leftText, $leftLen, " ", STR_PAD_RIGHT);
+    $printer->text($leftPadded . $rightText . "\n");
+}
+
+function printAlignedTextBold($printer, $leftLabel, $leftValue, $rightLabel, $rightValue, $width = 48) {
+    // Imprimir etiqueta izquierda en negrita
+    $printer->setEmphasis(true);
+    $printer->text($leftLabel);
+    $printer->setEmphasis(false);
+    
+    // Calcular espacios necesarios
+    $rightText = $rightLabel . $rightValue;
+    $rightLen = strlen($rightText);
+    $leftTotal = strlen($leftLabel . $leftValue);
+    $spaces = $width - $leftTotal - $rightLen;
+    
+    // Imprimir valor izquierdo y espacios
+    $printer->text($leftValue . str_repeat(" ", $spaces));
+    
+    // Imprimir etiqueta derecha en negrita
+    $printer->setEmphasis(true);
+    $printer->text($rightLabel);
+    $printer->setEmphasis(false);
+    $printer->text($rightValue . "\n");
+}
+
+function printTextBold($printer, $label, $value) {
+    $printer->setEmphasis(true);
+    $printer->text($label);
+    $printer->setEmphasis(false);
+    $printer->text($value . "\n");
+}
+
+// Get data from POST
+$dataPrint = null;
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST["dataPrint"])) {
+    // Si es string JSON, decodificar
+    if(is_string($_POST["dataPrint"])){
+        $dataPrint = json_decode($_POST["dataPrint"]);
+    } else {
+        // Si jQuery ya lo deserializó como array, convertir a objeto
+        $dataPrint = json_decode(json_encode($_POST["dataPrint"]));
+    }
+}
+
+if ($dataPrint) {
+    $PRINTER_NAME = $dataPrint->printer ?? 'POS-80C';
+    
+    try {
+        $connector = new WindowsPrintConnector($PRINTER_NAME);
+        $printer = new Printer($connector);
+        
+        // COMPANY HEADER
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->setTextSize(2, 2);
+        $printer->text(cutString(strtoupper($dataPrint->nombre_empresa), 24) . "\n");
+        
+        $printer->setTextSize(1, 1);
+        //$printer->text(cutString(strtoupper($dataPrint->giro_empresa ?? ''), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->direcion_empresa), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->rsocial_empresa), 48) . "\n");
+        //$printer->text("NRC: " . $dataPrint->nrc_empresa . " - NIT: " . $dataPrint->nit_empresa . "\n");
+        
+        printLinea($printer);
+        
+        // DOCUMENT INFO
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        //$printer->text("Control de Ticket Interno");
+        printAlignedTextBold($printer, "Fecha: ", $dataPrint->fecha, "Caja: ", $dataPrint->caja);
+        printAlignedTextBold($printer, "Vendedor: ", $dataPrint->vendedor, "Mesa: ", $dataPrint->mesa_orden);
+        printTextBold($printer, "Servicio: ", $dataPrint->servicio);
+
+        
+        printLinea($printer);
+        
+        // CUSTOMER INFO
+        if (isset($dataPrint->cliente) && $dataPrint->cliente != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Cliente: " . $dataPrint->cliente . "\n");
+            if (isset($dataPrint->direccion_cliente) && $dataPrint->direccion_cliente != "") {
+                $printer->text("Direccion: " . $dataPrint->direccion_cliente . "\n");
+            }
+            printLinea($printer);
+        }
+        
+        // PRODUCTS TABLE
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        $printer->setEmphasis(true);
+        $printer->text("CANT  DESCRIPCION               PRECIO  TOTAL\n");
+        printLinea($printer);
+        $printer->setEmphasis(false);
+        
+        foreach ($dataPrint->productos_normal as $producto) {
+            $cantidad = str_pad(number_format($producto->cant, 2), 5, " ", STR_PAD_RIGHT);
+            $precio = str_pad(number_format($producto->costo, 2), 7, " ", STR_PAD_LEFT);
+            $total = str_pad(number_format($producto->costo * $producto->cant, 2), 7, " ", STR_PAD_LEFT);
+            
+            $descripcion = wordwrap(strtoupper($producto->desc), 23, "\n", true);
+            $lineasDescripcion = explode("\n", $descripcion);
+            
+            $printer->text("$cantidad " . str_pad($lineasDescripcion[0], 23, " ") . " $precio $total\n");
+            
+            for ($i = 1; $i < count($lineasDescripcion); $i++) {
+                $printer->text("      " . $lineasDescripcion[$i] . "\n");
+            }
+            
+            // Imprimir acompañamientos si existen
+            if (isset($producto->acompanamientos) && $producto->acompanamientos != "") {
+                $printer->setEmphasis(true);
+                $printer->text("      CON: ");
+                $printer->setEmphasis(false);
+                $printer->text(strtoupper($producto->acompanamientos) . "\n");
+            }
+            
+            // Imprimir notas si existen
+            if (isset($producto->notas) && $producto->notas != "") {
+                $printer->setEmphasis(true);
+                $printer->text("      NOTA: ");
+                $printer->setEmphasis(false);
+                $printer->text(strtoupper($producto->notas) . "\n");
+            }
+        }
+        
+        printLinea($printer);
+        
+        // TOTALS
+        $printer->setJustification(Printer::JUSTIFY_RIGHT);
+        $printer->setEmphasis(true);
+        $printer->setTextSize(1, 2);
+        $printer->text("TOTAL $" . number_format($dataPrint->totales->totalTotal, 2) . "\n");
+        $printer->setTextSize(1, 1);
+        $printer->setEmphasis(false);
+        
+        $printer->text("EFECTIVO $" . number_format($dataPrint->efectivo, 2) . "\n");
+        $printer->text("CAMBIO $" . number_format($dataPrint->cambio, 2) . "\n");
+        
+        if (isset($dataPrint->pos) && floatval($dataPrint->pos) > 0) {
+            $printer->text("POS $" . number_format($dataPrint->pos, 2) . "\n");
+        }
+
+        printLinea($printer);
+
+        // NOTAS DE ORDEN
+        if (isset($dataPrint->notas_orden) && $dataPrint->notas_orden != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->setEmphasis(true);
+            $printer->text("NOTAS ORDEN:\n");
+            $printer->setEmphasis(false);
+            $notasLines = wordwrap($dataPrint->notas_orden, 48, "\n", true);
+            foreach (explode("\n", $notasLines) as $linea) {
+                $printer->text($linea . "\n");
+            }
+        }
+        
+        printLinea($printer);
+
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("\n");
+        $printer->text("REF.: " . ($dataPrint->referencia) . "\n");
+        
+        /*
+        if (isset($dataPrint->notas) && $dataPrint->notas != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Notas: " . $dataPrint->notas . "\n");
+            printLinea($printer);
+        }
+        */
+        /*
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("\n");
+        
+        if (isset($dataPrint->mensaje_ticket) && $dataPrint->mensaje_ticket != "") {
+            $mensajeLines = wordwrap($dataPrint->mensaje_ticket, 48, "\n", true);
+            foreach (explode("\n", $mensajeLines) as $linea) {
+                $printer->text($linea . "\n");
+            }
+        }
+        */
+        
+        // FINISH
+        $printer->feed(2);
+        $printer->cut();
+        $printer->close();
+        
+        echo json_encode([
+            "status" => "success",
+            "message" => "Recibo impreso correctamente."
+        ]);
+        
+    } catch (Exception $e) {
+        echo json_encode([
+            "status" => "error",
+            "message" => "Error al imprimir: " . $e->getMessage()
+        ]);
+    }
+} else {
+    echo json_encode([
+        "status" => "error",
+        "message" => "No se recibieron datos para imprimir."
+    ]);
+}
+?>

+ 241 - 0
print_express/precuenta_express.php

@@ -0,0 +1,241 @@
+<?php
+if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+    header("Access-Control-Allow-Origin: *");
+    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
+    http_response_code(204);
+    exit;
+}
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
+header("Access-Control-Allow-Headers: Content-Type, Authorization");
+
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('log_errors', 1);
+ini_set('error_log', __DIR__ . '/logs/error.log');
+
+require __DIR__ . '/../vendor/autoload.php';
+use Mike42\Escpos\Printer;
+use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
+
+// Helper functions
+function printLinea($printer, $char = "-", $width = 48) {
+    $printer->text(str_repeat($char, $width) . "\n");
+}
+
+function cutString($text, $maxLength) {
+    return substr($text, 0, $maxLength);
+}
+
+function printAlignedText($printer, $leftText, $rightText, $width = 48) {
+    $rightLen = strlen($rightText);
+    $leftLen = $width - $rightLen;
+    $leftPadded = str_pad($leftText, $leftLen, " ", STR_PAD_RIGHT);
+    $printer->text($leftPadded . $rightText . "\n");
+}
+
+function printAlignedTextBold($printer, $leftLabel, $leftValue, $rightLabel, $rightValue, $width = 48) {
+    // Imprimir etiqueta izquierda en negrita
+    $printer->setEmphasis(true);
+    $printer->text($leftLabel);
+    $printer->setEmphasis(false);
+    
+    // Calcular espacios necesarios
+    $rightText = $rightLabel . $rightValue;
+    $rightLen = strlen($rightText);
+    $leftTotal = strlen($leftLabel . $leftValue);
+    $spaces = $width - $leftTotal - $rightLen;
+    
+    // Imprimir valor izquierdo y espacios
+    $printer->text($leftValue . str_repeat(" ", $spaces));
+    
+    // Imprimir etiqueta derecha en negrita
+    $printer->setEmphasis(true);
+    $printer->text($rightLabel);
+    $printer->setEmphasis(false);
+    $printer->text($rightValue . "\n");
+}
+
+function printTextBold($printer, $label, $value) {
+    $printer->setEmphasis(true);
+    $printer->text($label);
+    $printer->setEmphasis(false);
+    $printer->text($value . "\n");
+}
+
+// Get data from POST
+$dataPrint = null;
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST["dataPrint"])) {
+    // Si es string JSON, decodificar
+    if(is_string($_POST["dataPrint"])){
+        $dataPrint = json_decode($_POST["dataPrint"]);
+    } else {
+        // Si jQuery ya lo deserializó como array, convertir a objeto
+        $dataPrint = json_decode(json_encode($_POST["dataPrint"]));
+    }
+}
+
+if ($dataPrint) {
+    $PRINTER_NAME = $dataPrint->printer ?? 'POS-80C';
+    
+    try {
+        $connector = new WindowsPrintConnector($PRINTER_NAME);
+        $printer = new Printer($connector);
+        
+        // COMPANY HEADER
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->setTextSize(2, 2);
+        $printer->text(cutString(strtoupper($dataPrint->nombre_empresa), 24) . "\n");
+        
+        $printer->setTextSize(1, 1);
+        //$printer->text(cutString(strtoupper($dataPrint->giro_empresa ?? ''), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->direcion_empresa), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->rsocial_empresa), 48) . "\n");
+        //$printer->text("NRC: " . $dataPrint->nrc_empresa . " - NIT: " . $dataPrint->nit_empresa . "\n");
+        
+        printLinea($printer);
+        
+        // DOCUMENT INFO
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        //$printer->text("Control de Ticket Interno");
+        printAlignedTextBold($printer, "Fecha: ", $dataPrint->fecha, "Caja: ", $dataPrint->caja);
+        printAlignedTextBold($printer, "Vendedor: ", $dataPrint->vendedor, "Mesa: ", $dataPrint->mesa_orden);
+        printTextBold($printer, "Servicio: ", $dataPrint->servicio);
+
+        
+        printLinea($printer);
+        
+        // CUSTOMER INFO
+        if (isset($dataPrint->cliente) && $dataPrint->cliente != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Cliente: " . $dataPrint->cliente . "\n");
+            if (isset($dataPrint->direccion_cliente) && $dataPrint->direccion_cliente != "") {
+                $printer->text("Direccion: " . $dataPrint->direccion_cliente . "\n");
+            }
+            printLinea($printer);
+        }
+        
+        // PRODUCTS TABLE
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        $printer->setEmphasis(true);
+        $printer->text("CANT  DESCRIPCION               PRECIO  TOTAL\n");
+        printLinea($printer);
+        $printer->setEmphasis(false);
+        
+        foreach ($dataPrint->productos_normal as $producto) {
+            $cantidad = str_pad(number_format($producto->cant, 2), 5, " ", STR_PAD_RIGHT);
+            $precio = str_pad(number_format($producto->costo, 2), 7, " ", STR_PAD_LEFT);
+            $total = str_pad(number_format($producto->costo * $producto->cant, 2), 7, " ", STR_PAD_LEFT);
+            
+            $descripcion = wordwrap(strtoupper($producto->desc), 23, "\n", true);
+            $lineasDescripcion = explode("\n", $descripcion);
+            
+            $printer->text("$cantidad " . str_pad($lineasDescripcion[0], 23, " ") . " $precio $total\n");
+            
+            for ($i = 1; $i < count($lineasDescripcion); $i++) {
+                $printer->text("      " . $lineasDescripcion[$i] . "\n");
+            }
+            
+            // Imprimir acompañamientos si existen
+            if (isset($producto->acompanamientos) && $producto->acompanamientos != "") {
+                $printer->setEmphasis(true);
+                $printer->text("      CON: ");
+                $printer->setEmphasis(false);
+                $printer->text(strtoupper($producto->acompanamientos) . "\n");
+            }
+            
+            /*
+            if (isset($producto->notas) && $producto->notas != "") {
+                $printer->setEmphasis(true);
+                $printer->text("      NOTA: ");
+                $printer->setEmphasis(false);
+                $printer->text(strtoupper($producto->notas) . "\n");
+            }
+            */
+        }
+        
+        printLinea($printer);
+        
+        // TOTALS
+        $printer->setJustification(Printer::JUSTIFY_RIGHT);
+        $printer->setEmphasis(true);
+        $printer->setTextSize(1, 2);
+        $printer->text("TOTAL $" . number_format($dataPrint->totales->totalTotal, 2) . "\n");
+        $printer->setTextSize(1, 1);
+        $printer->setEmphasis(false);
+        
+        $printer->text("EFECTIVO $" . number_format($dataPrint->efectivo, 2) . "\n");
+        $printer->text("CAMBIO $" . number_format($dataPrint->cambio, 2) . "\n");
+        
+        if (isset($dataPrint->pos) && floatval($dataPrint->pos) > 0) {
+            $printer->text("POS $" . number_format($dataPrint->pos, 2) . "\n");
+        }
+
+        printLinea($printer);
+
+        /*
+        if (isset($dataPrint->notas_orden) && $dataPrint->notas_orden != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->setEmphasis(true);
+            $printer->text("NOTAS ORDEN:\n");
+            $printer->setEmphasis(false);
+            $notasLines = wordwrap($dataPrint->notas_orden, 48, "\n", true);
+            foreach (explode("\n", $notasLines) as $linea) {
+                $printer->text($linea . "\n");
+            }
+        }
+        */ 
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("Comprobante de Control Interno\n");
+        
+        printLinea($printer);
+
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("\n");
+        $printer->text("REF.: " . ($dataPrint->referencia) . "\n");
+        
+        /*
+        if (isset($dataPrint->notas) && $dataPrint->notas != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Notas: " . $dataPrint->notas . "\n");
+            printLinea($printer);
+        }
+        */
+        /*
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("\n");
+        
+        if (isset($dataPrint->mensaje_ticket) && $dataPrint->mensaje_ticket != "") {
+            $mensajeLines = wordwrap($dataPrint->mensaje_ticket, 48, "\n", true);
+            foreach (explode("\n", $mensajeLines) as $linea) {
+                $printer->text($linea . "\n");
+            }
+        }
+        */
+        
+        // FINISH
+        $printer->feed(2);
+        $printer->cut();
+        $printer->close();
+        
+        echo json_encode([
+            "status" => "success",
+            "message" => "Recibo impreso correctamente."
+        ]);
+        
+    } catch (Exception $e) {
+        echo json_encode([
+            "status" => "error",
+            "message" => "Error al imprimir: " . $e->getMessage()
+        ]);
+    }
+} else {
+    echo json_encode([
+        "status" => "error",
+        "message" => "No se recibieron datos para imprimir."
+    ]);
+}
+?>

+ 172 - 0
print_express/recibo_express.php

@@ -0,0 +1,172 @@
+<?php
+if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+    header("Access-Control-Allow-Origin: *");
+    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
+    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
+    http_response_code(204);
+    exit;
+}
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
+header("Access-Control-Allow-Headers: Content-Type, Authorization");
+
+error_reporting(E_ALL);
+ini_set('display_errors', 0);
+ini_set('log_errors', 1);
+ini_set('error_log', __DIR__ . '/logs/error.log');
+
+require __DIR__ . '/../vendor/autoload.php';
+use Mike42\Escpos\Printer;
+use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
+
+// Helper functions
+function printLinea($printer, $char = "-", $width = 48) {
+    $printer->text(str_repeat($char, $width) . "\n");
+}
+
+function cutString($text, $maxLength) {
+    return substr($text, 0, $maxLength);
+}
+
+function printAlignedText($printer, $leftText, $rightText, $width = 48) {
+    $rightLen = strlen($rightText);
+    $leftLen = $width - $rightLen;
+    $leftPadded = str_pad($leftText, $leftLen, " ", STR_PAD_RIGHT);
+    $printer->text($leftPadded . $rightText . "\n");
+}
+
+// Get data from POST
+$dataPrint = null;
+if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST["dataPrint"])) {
+    $dataPrint = json_decode($_POST["dataPrint"]);
+}
+
+if ($dataPrint) {
+    $PRINTER_NAME = $dataPrint->printer ?? 'POS-80C';
+    
+    try {
+        $connector = new WindowsPrintConnector($PRINTER_NAME);
+        $printer = new Printer($connector);
+        
+        // COMPANY HEADER
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->setTextSize(2, 2);
+        $printer->text(cutString(strtoupper($dataPrint->nombre_empresa), 24) . "\n");
+        
+        $printer->setTextSize(1, 1);
+        //$printer->text(cutString(strtoupper($dataPrint->giro_empresa ?? ''), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->direcion_empresa), 48) . "\n");
+        //$printer->text(cutString(strtoupper($dataPrint->rsocial_empresa), 48) . "\n");
+        //$printer->text("NRC: " . $dataPrint->nrc_empresa . " - NIT: " . $dataPrint->nit_empresa . "\n");
+        
+        printLinea($printer);
+        
+        // DOCUMENT INFO
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        printAlignedText($printer, "Fecha: " . $dataPrint->fecha, "Caja: " . $dataPrint->caja);
+        printAlignedText($printer, "Vendedor: " . $dataPrint->vendedor, "Cajero: " . $dataPrint->cajero);
+        
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->setEmphasis(true);
+        $printer->text("RECIBO\n");
+        $printer->text("No. " . $dataPrint->doc_numero . "\n");
+        $printer->setEmphasis(false);
+        
+        printLinea($printer);
+        
+        // CUSTOMER INFO
+        if (isset($dataPrint->cliente) && $dataPrint->cliente != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Cliente: " . $dataPrint->cliente . "\n");
+            if (isset($dataPrint->direccion_cliente) && $dataPrint->direccion_cliente != "") {
+                $printer->text("Direccion: " . $dataPrint->direccion_cliente . "\n");
+            }
+            printLinea($printer);
+        }
+        
+        // PRODUCTS TABLE
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        $printer->setEmphasis(true);
+        $printer->text("CANT  DESCRIPCION               PRECIO  TOTAL\n");
+        printLinea($printer);
+        $printer->setEmphasis(false);
+        
+        foreach ($dataPrint->productos_normal as $producto) {
+            $cantidad = str_pad(number_format($producto->cant, 2), 5, " ", STR_PAD_RIGHT);
+            $precio = str_pad(number_format($producto->costo, 2), 7, " ", STR_PAD_LEFT);
+            $total = str_pad(number_format($producto->costo * $producto->cant, 2), 7, " ", STR_PAD_LEFT);
+            
+            $descripcion = wordwrap(strtoupper($producto->desc), 23, "\n", true);
+            $lineasDescripcion = explode("\n", $descripcion);
+            
+            $printer->text("$cantidad " . str_pad($lineasDescripcion[0], 23, " ") . " $precio $total\n");
+            
+            for ($i = 1; $i < count($lineasDescripcion); $i++) {
+                $printer->text("      " . $lineasDescripcion[$i] . "\n");
+            }
+        }
+        
+        printLinea($printer);
+        
+        // TOTALS
+        $printer->setJustification(Printer::JUSTIFY_RIGHT);
+        $printer->setEmphasis(true);
+        $printer->setTextSize(1, 2);
+        $printer->text("TOTAL $" . number_format($dataPrint->totales->totalTotal, 2) . "\n");
+        $printer->setTextSize(1, 1);
+        $printer->setEmphasis(false);
+        
+        $printer->text("EFECTIVO $" . number_format($dataPrint->efectivo, 2) . "\n");
+        
+        if (isset($dataPrint->pos) && floatval($dataPrint->pos) > 0) {
+            $printer->text("POS $" . number_format($dataPrint->pos, 2) . "\n");
+        }
+        
+        $printer->setJustification(Printer::JUSTIFY_LEFT);
+        printAlignedText($printer, "REF.: " . $dataPrint->referencia, "CAMBIO $" . number_format($dataPrint->cambio, 2));
+        
+        printLinea($printer);
+        
+        /*
+        if (isset($dataPrint->notas) && $dataPrint->notas != "") {
+            $printer->setJustification(Printer::JUSTIFY_LEFT);
+            $printer->text("Notas: " . $dataPrint->notas . "\n");
+            printLinea($printer);
+        }
+        */
+        
+        // FINAL MESSAGE
+        $printer->setJustification(Printer::JUSTIFY_CENTER);
+        $printer->text("\n");
+        
+        if (isset($dataPrint->mensaje_ticket) && $dataPrint->mensaje_ticket != "") {
+            $mensajeLines = wordwrap($dataPrint->mensaje_ticket, 48, "\n", true);
+            foreach (explode("\n", $mensajeLines) as $linea) {
+                $printer->text($linea . "\n");
+            }
+        }
+        
+        // FINISH
+        $printer->feed(2);
+        $printer->cut();
+        $printer->close();
+        
+        echo json_encode([
+            "status" => "success",
+            "message" => "Recibo impreso correctamente."
+        ]);
+        
+    } catch (Exception $e) {
+        echo json_encode([
+            "status" => "error",
+            "message" => "Error al imprimir: " . $e->getMessage()
+        ]);
+    }
+} else {
+    echo json_encode([
+        "status" => "error",
+        "message" => "No se recibieron datos para imprimir."
+    ]);
+}
+?>

+ 1 - 1
comanda_movil.php → print_movil/comanda_movil.php

@@ -23,7 +23,7 @@ ini_set('display_errors', 0);
 ini_set('log_errors', 1);
 ini_set('error_log', 'logs/error.log');
 
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 use Mike42\Escpos\Printer;
 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
 

+ 1 - 1
precuenta_movil.php → print_movil/precuenta_movil.php

@@ -23,7 +23,7 @@ ini_set('display_errors', 0);
 ini_set('log_errors', 1);
 ini_set('error_log', 'logs/error.log');
 
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
 use Mike42\Escpos\Printer;
 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
 

+ 60 - 69
recibo.php

@@ -33,15 +33,19 @@ $dataPrint = null;
 $isc = '';
 
 if(isset($_POST["dataPrint"])){
-    // jQuery envía el objeto como está, necesitamos convertirlo a array
-    $dataPrint = is_array($_POST["dataPrint"]) ? $_POST["dataPrint"] : json_decode(json_encode($_POST["dataPrint"]), true);
+    // jQuery envía JSON.stringify, necesitamos decodificarlo
+    $dataPrint = $_POST["dataPrint"];
+    if(is_string($dataPrint)){
+        $dataPrint = json_decode($dataPrint, true);
+    }
 }
 
-if(!$dataPrint){
+if(!$dataPrint || !is_array($dataPrint)){
     echo json_encode([
         'success' => false,
         'status' => 'error', 
-        'message' => 'No se recibieron datos para imprimir'
+        'message' => 'No se recibieron datos para imprimir o formato incorrecto',
+        'received' => isset($_POST["dataPrint"]) ? substr(print_r($_POST["dataPrint"], true), 0, 200) : 'nada'
     ]);
     exit;
 }
@@ -56,50 +60,40 @@ try {
     // ENCABEZADO
     $printer->setJustification(Printer::JUSTIFY_CENTER);
     $printer->setTextSize(2, 2);
-    $printer->text($dataPrint['nombre_empresa'] . "\n");
-    $printer->setTextSize(1, 1);
     
-    if (!empty($dataPrint['direcion_empresa'])) {
-        $printer->text($dataPrint['direcion_empresa'] . "\n");
-    }
-    
-    if (!empty($dataPrint['nit_empresa'])) {
-        $printer->text("NIT: " . $dataPrint['nit_empresa'] . "\n");
-    }
+    $nombreEmpresa = isset($dataPrint['nombre_empresa']) ? $dataPrint['nombre_empresa'] : 
+                     (isset($dataPrint['empresa_nombre']) ? $dataPrint['empresa_nombre'] : 'EMPRESA');
+    $printer->text($nombreEmpresa . "\n");
+    $printer->setTextSize(1, 1);
     
-    if (!empty($dataPrint['nrc_empresa'])) {
-        $printer->text("NRC: " . $dataPrint['nrc_empresa'] . "\n");
+    $direccion = isset($dataPrint['direcion_empresa']) ? $dataPrint['direcion_empresa'] : 
+                 (isset($dataPrint['empresa_direccion']) ? $dataPrint['empresa_direccion'] : '');
+    if (!empty($direccion)) {
+        $printer->text($direccion . "\n");
     }
     
-    $printer->text(str_repeat("=", 45) . "\n");
+    $printer->text(str_repeat("=", 48) . "\n");
     $printer->setEmphasis(true);
     $printer->text("R E C I B O\n");
     $printer->setEmphasis(false);
-    $printer->text(str_repeat("=", 45) . "\n");
+    $printer->text(str_repeat("=", 48) . "\n");
     
     // INFORMACIÓN DEL RECIBO
     $printer->setJustification(Printer::JUSTIFY_LEFT);
     
-    if (!empty($dataPrint['doc_numero'])) {
-        $printer->setEmphasis(true);
-        $printer->text("Recibo #: ");
-        $printer->setEmphasis(false);
-        $printer->text($dataPrint['doc_numero'] . "\n");
-    }
-    
-    if (!empty($dataPrint['fecha'])) {
-        $printer->setEmphasis(true);
-        $printer->text("Fecha: ");
-        $printer->setEmphasis(false);
-        $printer->text($dataPrint['fecha'] . "\n");
-    }
+    $fecha = isset($dataPrint['fecha']) ? $dataPrint['fecha'] : date('d-m-Y H:i:s');
+    $printer->setEmphasis(true);
+    $printer->text("Fecha: ");
+    $printer->setEmphasis(false);
+    $printer->text($fecha . "\n");
     
+    /*
     if (!empty($dataPrint['referencia'])) {
         $printer->setEmphasis(true);
         $printer->text("Referencia: ");
         $printer->setEmphasis(false);
         $printer->text($dataPrint['referencia'] . "\n");
-    }
+    }*/
     
     if (!empty($dataPrint['cliente'])) {
         $printer->setEmphasis(true);
@@ -108,27 +102,22 @@ try {
         $printer->text($dataPrint['cliente'] . "\n");
     }
     
-    if (!empty($dataPrint['vendedor'])) {
-        $printer->setEmphasis(true);
-        $printer->text("Vendedor: ");
-        $printer->setEmphasis(false);
-        $printer->text($dataPrint['vendedor'] . "\n");
-    }
-    
+    /*
     if (!empty($dataPrint['caja'])) {
         $printer->setEmphasis(true);
         $printer->text("Caja: ");
         $printer->setEmphasis(false);
         $printer->text($dataPrint['caja'] . "\n");
-    }
+    }*/
+    
     
-    $printer->text(str_repeat("-", 45) . "\n");
+    $printer->text(str_repeat("-", 48) . "\n");
     
     // ENCABEZADO DE TABLA
     $printer->setEmphasis(true);
-    $printer->text("CANT  DESCRIPCION               TOTAL\n");
+    $printer->text("CANT    DESCRIPCION                        TOTAL\n");
     $printer->setEmphasis(false);
-    $printer->text(str_repeat("-", 45) . "\n");
+    $printer->text(str_repeat("-", 48) . "\n");
     
     // PRODUCTOS
     $subtotal = 0;
@@ -145,45 +134,54 @@ try {
             $subtotal += $total;
             
             // Línea del producto - cant y descripción
-            $cantPad = str_pad($cant, 4);
+            $cantTexto = $cant . "x";
             $descCorto = substr($desc, 0, 25);
             $totalStr = "$" . number_format($total, 2);
             
-            $printer->text($cantPad . "x " . str_pad($descCorto, 27) . str_pad($totalStr, 10, " ", STR_PAD_LEFT) . "\n");
+            $printer->text(str_pad($cantTexto, 5) . " " . str_pad($descCorto, 36) . str_pad($totalStr, 1, " ", STR_PAD_LEFT) . "\n");
         }
     }
     
-    $printer->text(str_repeat("=", 45) . "\n");
+    $printer->text(str_repeat("=", 48) . "\n");
     
     // TOTALES
     $printer->setJustification(Printer::JUSTIFY_RIGHT);
     
     $totales = isset($dataPrint['totales']) && is_array($dataPrint['totales']) ? $dataPrint['totales'] : [];
     
-    $totalGrabadas = isset($totales['totalGrabadas']) ? floatval(str_replace(',', '', $totales['totalGrabadas'])) : $subtotal;
-    $descuento = isset($totales['descuento']) ? floatval(str_replace(',', '', $totales['descuento'])) : 0;
-    $propina = isset($totales['propina']) ? floatval(str_replace(',', '', $totales['propina'])) : 0;
-    $totalTotal = isset($totales['totalTotal']) ? floatval(str_replace(',', '', $totales['totalTotal'])) : 0;
+    // Función helper para limpiar valores numéricos
+    $limpiarNumero = function($valor) {
+        if(is_numeric($valor)) return floatval($valor);
+        if(is_string($valor)) return floatval(str_replace(',', '', $valor));
+        return 0;
+    };
+    
+    $descuento = $limpiarNumero(isset($totales['descuento']) ? $totales['descuento'] : 0);
+    $propina = $limpiarNumero(isset($totales['propina']) ? $totales['propina'] : 0);
+    $totalTotal = $limpiarNumero(isset($totales['totalTotal']) ? $totales['totalTotal'] : 0);
     
-    $printer->text("Subtotal:  $" . number_format($totalGrabadas, 2) . "\n");
+    $efectivo = $limpiarNumero(isset($dataPrint['efectivo']) ? $dataPrint['efectivo'] : 0);
+    $pos = $limpiarNumero(isset($dataPrint['pos']) ? $dataPrint['pos'] : 0);
+    $cambio = $limpiarNumero(isset($dataPrint['cambio']) ? $dataPrint['cambio'] : 0);
+    
+    // TOTAL (PRIMERO)
+    $printer->setEmphasis(true);
+    $printer->setTextSize(2, 1);
+    $printer->text("TOTAL: $" . number_format($totalTotal, 2) . "\n");
+    $printer->setTextSize(1, 1);
+    $printer->setEmphasis(false);
     
+    // DESCUENTO
     if ($descuento > 0) {
         $printer->text("Descuento: -$" . number_format($descuento, 2) . "\n");
     }
     
+    // PROPINA
     if ($propina > 0) {
         $printer->text("Propina:   $" . number_format($propina, 2) . "\n");
     }
     
-
-    
-    // FORMA DE PAGO
-    $printer->setJustification(Printer::JUSTIFY_RIGHT);
-    
-    $efectivo = isset($dataPrint['efectivo']) ? floatval($dataPrint['efectivo']) : 0;
-    $pos = isset($dataPrint['pos']) ? floatval($dataPrint['pos']) : 0;
-    $cambio = isset($dataPrint['cambio']) ? floatval($dataPrint['cambio']) : 0;
-    
+    // MÉTODO DE PAGO
     if ($efectivo > 0) {
         $printer->text("Efectivo:  $" . number_format($efectivo, 2) . "\n");
     }
@@ -192,17 +190,10 @@ try {
         $printer->text("POS/Tarjeta: $" . number_format($pos, 2) . "\n");
     }
     
-    if ($cambio > 0) {
-        $printer->text("Cambio:    $" . number_format($cambio, 2) . "\n");
-    }
+    // CAMBIO (SIEMPRE MOSTRAR)
+    $printer->text("Cambio:    $" . number_format($cambio, 2) . "\n");
     
-    $printer->text(str_repeat("-", 45) . "\n");
-    $printer->setEmphasis(true);
-    $printer->setTextSize(2, 1);
-    $printer->text("TOTAL: $" . number_format($totalTotal, 2) . "\n");
-    $printer->setTextSize(1, 1);
-    $printer->setEmphasis(false);
-    $printer->text(str_repeat("=", 45) . "\n");
+    $printer->text(str_repeat("=", 48) . "\n");
     
     // MENSAJE FINAL
     $printer->setJustification(Printer::JUSTIFY_CENTER);