|
@@ -33,15 +33,19 @@ $dataPrint = null;
|
|
|
$isc = '';
|
|
$isc = '';
|
|
|
|
|
|
|
|
if(isset($_POST["dataPrint"])){
|
|
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([
|
|
echo json_encode([
|
|
|
'success' => false,
|
|
'success' => false,
|
|
|
'status' => 'error',
|
|
'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;
|
|
exit;
|
|
|
}
|
|
}
|
|
@@ -56,50 +60,40 @@ try {
|
|
|
// ENCABEZADO
|
|
// ENCABEZADO
|
|
|
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
|
$printer->setTextSize(2, 2);
|
|
$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->setEmphasis(true);
|
|
|
$printer->text("R E C I B O\n");
|
|
$printer->text("R E C I B O\n");
|
|
|
$printer->setEmphasis(false);
|
|
$printer->setEmphasis(false);
|
|
|
- $printer->text(str_repeat("=", 45) . "\n");
|
|
|
|
|
|
|
+ $printer->text(str_repeat("=", 48) . "\n");
|
|
|
|
|
|
|
|
// INFORMACIÓN DEL RECIBO
|
|
// INFORMACIÓN DEL RECIBO
|
|
|
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
|
$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'])) {
|
|
if (!empty($dataPrint['referencia'])) {
|
|
|
$printer->setEmphasis(true);
|
|
$printer->setEmphasis(true);
|
|
|
$printer->text("Referencia: ");
|
|
$printer->text("Referencia: ");
|
|
|
$printer->setEmphasis(false);
|
|
$printer->setEmphasis(false);
|
|
|
$printer->text($dataPrint['referencia'] . "\n");
|
|
$printer->text($dataPrint['referencia'] . "\n");
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
if (!empty($dataPrint['cliente'])) {
|
|
if (!empty($dataPrint['cliente'])) {
|
|
|
$printer->setEmphasis(true);
|
|
$printer->setEmphasis(true);
|
|
@@ -108,27 +102,22 @@ try {
|
|
|
$printer->text($dataPrint['cliente'] . "\n");
|
|
$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'])) {
|
|
if (!empty($dataPrint['caja'])) {
|
|
|
$printer->setEmphasis(true);
|
|
$printer->setEmphasis(true);
|
|
|
$printer->text("Caja: ");
|
|
$printer->text("Caja: ");
|
|
|
$printer->setEmphasis(false);
|
|
$printer->setEmphasis(false);
|
|
|
$printer->text($dataPrint['caja'] . "\n");
|
|
$printer->text($dataPrint['caja'] . "\n");
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- $printer->text(str_repeat("-", 45) . "\n");
|
|
|
|
|
|
|
+ $printer->text(str_repeat("-", 48) . "\n");
|
|
|
|
|
|
|
|
// ENCABEZADO DE TABLA
|
|
// ENCABEZADO DE TABLA
|
|
|
$printer->setEmphasis(true);
|
|
$printer->setEmphasis(true);
|
|
|
- $printer->text("CANT DESCRIPCION TOTAL\n");
|
|
|
|
|
|
|
+ $printer->text("CANT DESCRIPCION TOTAL\n");
|
|
|
$printer->setEmphasis(false);
|
|
$printer->setEmphasis(false);
|
|
|
- $printer->text(str_repeat("-", 45) . "\n");
|
|
|
|
|
|
|
+ $printer->text(str_repeat("-", 48) . "\n");
|
|
|
|
|
|
|
|
// PRODUCTOS
|
|
// PRODUCTOS
|
|
|
$subtotal = 0;
|
|
$subtotal = 0;
|
|
@@ -145,45 +134,54 @@ try {
|
|
|
$subtotal += $total;
|
|
$subtotal += $total;
|
|
|
|
|
|
|
|
// Línea del producto - cant y descripción
|
|
// Línea del producto - cant y descripción
|
|
|
- $cantPad = str_pad($cant, 4);
|
|
|
|
|
|
|
+ $cantTexto = $cant . "x";
|
|
|
$descCorto = substr($desc, 0, 25);
|
|
$descCorto = substr($desc, 0, 25);
|
|
|
$totalStr = "$" . number_format($total, 2);
|
|
$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
|
|
// TOTALES
|
|
|
$printer->setJustification(Printer::JUSTIFY_RIGHT);
|
|
$printer->setJustification(Printer::JUSTIFY_RIGHT);
|
|
|
|
|
|
|
|
$totales = isset($dataPrint['totales']) && is_array($dataPrint['totales']) ? $dataPrint['totales'] : [];
|
|
$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) {
|
|
if ($descuento > 0) {
|
|
|
$printer->text("Descuento: -$" . number_format($descuento, 2) . "\n");
|
|
$printer->text("Descuento: -$" . number_format($descuento, 2) . "\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // PROPINA
|
|
|
if ($propina > 0) {
|
|
if ($propina > 0) {
|
|
|
$printer->text("Propina: $" . number_format($propina, 2) . "\n");
|
|
$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) {
|
|
if ($efectivo > 0) {
|
|
|
$printer->text("Efectivo: $" . number_format($efectivo, 2) . "\n");
|
|
$printer->text("Efectivo: $" . number_format($efectivo, 2) . "\n");
|
|
|
}
|
|
}
|
|
@@ -192,17 +190,10 @@ try {
|
|
|
$printer->text("POS/Tarjeta: $" . number_format($pos, 2) . "\n");
|
|
$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
|
|
// MENSAJE FINAL
|
|
|
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
$printer->setJustification(Printer::JUSTIFY_CENTER);
|