terminado a falta de pruebas

This commit is contained in:
2025-04-26 10:50:59 +02:00
parent ef173ab0fc
commit b5b86b4164
6 changed files with 159 additions and 69 deletions

View File

@ -331,63 +331,6 @@ class LogisticaService
];
}
public static function imprimirEtiquetas($envio_id, $ids)
{
$array = [
"printer" => "LABPRINT-1",
"header" => [
"_FORMAT" => "E:PEDIDO.ZPL",
"_QUANTITY" => 1,
"_PRINBTERNAME" => "Printer 1",
"_JOBNAME" => "LBL101"
],
"labels" => [
/* Ejemplo etiqueta
[
"cliente" => "Cliente Potencial",
"titulo" => "[1234] TEST OLIVEROS",
"cantidad" => 100,
"tirada" => 50,
"cajas" => 1,
"ean" => null,
"nombre" => "___Nombre___",
"direccion" => "C/ test n10, Madrid, 12345, España",
"notas" => "Nota....",
"refcliente" => "Refclient:1234",
"npedido" => "1234"
]
*/
]
];
$EnvioModel = model('App\Models\Logistica\EnvioModel');
$EnvioLineasModel = model('App\Models\Logistica\EnvioLineaModel');
$envios = $EnvioModel->whereIn('id', $ids)->findAll();
if (empty($envios)) {
return [
'status' => false,
'message' => lang('Logistica.errors.noEnvio'),
];
}
foreach ($envios as $envio) {
$lineasEnvio = $EnvioLineasModel->where('envio_id', $envio->id)->findAll();
if (empty($lineasEnvio)) {
return [
'status' => false,
'message' => lang('Logistica.errors.noEnvioLineas'),
];
}
}
return [
'status' => true,
'data' => $envios,
];
}
public static function finalizarEnvio($envio_id, $finalizar_ot = false)
{
@ -475,4 +418,66 @@ class LogisticaService
}
return $data_return;
}
public static function generateEtiquetasTitulos($envio, $lineas, $printer, $cajas)
{
$data = [
"printer" => $printer->name,
"header" => [
"_FORMAT" => "E:PEDIDO.ZPL",
"_QUANTITY" => 1,
"_PRINBTERNAME" => $printer->name,
"_JOBNAME" => "LBL101"
],
];
foreach ($lineas as $linea) {
$data["labels"][] = [
"cliente" => $envio->cliente,
"titulo" => "[" . $linea->pedido_id . "] - " . $linea->titulo,
"cantidad" => $linea->unidades_envio,
"tirada" => $linea->unidades_total,
"cajas" => $cajas,
"ean" => null,
"nombre" => $envio->att,
"direccion" => $envio->direccion,
"notas" => "",
"refcliente" => $linea->refcliente,
"npedido" => $linea->pedido_id
];
}
$servicioImpresora = new ImpresoraEtiquetaService();
$xml = $servicioImpresora->createEtiqueta($data);
if($xml == null){
return [
'status' => false,
'message' => lang('Logistica.errors.noEtiquetas'),
];
}
$sk_environment = getenv('SK_ENVIRONMENT');
if($sk_environment == 'production'){
$status = $servicioImpresora->sendToImpresoraEtiqueta("ETIQUETA", $xml, $printer);
if ($status) {
return [
'status' => true,
'message' => lang('Logistica.success.imprimirEtiquetas'),
'data' => $xml
];
} else {
return [
'status' => false,
'message' => lang('Logistica.errors.noEtiquetas'),
];
}
}else{
return [
'status' => true,
'message' => lang('Logistica.success.imprimirEtiquetas'),
'data' => $xml
];
}
}
}