mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'add/print_labels_maquinista' into 'main'
terminado See merge request jjimenez/safekat!775
This commit is contained in:
@ -785,7 +785,7 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func
|
|||||||
$routes->post("fa/tareas/reset",'Ordentrabajo::delete_orden_trabajo_fa_tareas');
|
$routes->post("fa/tareas/reset",'Ordentrabajo::delete_orden_trabajo_fa_tareas');
|
||||||
$routes->post('maquinas/ots','Ordentrabajo::store_maquina_ordenes_trabajo');
|
$routes->post('maquinas/ots','Ordentrabajo::store_maquina_ordenes_trabajo');
|
||||||
$routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado');
|
$routes->post('maquinas/ots/estado','Ordentrabajo::update_maquina_ordenes_trabajo_estado');
|
||||||
|
|
||||||
|
|
||||||
/**DELETES */
|
/**DELETES */
|
||||||
$routes->delete("portada/(:num)", 'Ordentrabajo::delete_orden_trabajo_portada/$1');
|
$routes->delete("portada/(:num)", 'Ordentrabajo::delete_orden_trabajo_portada/$1');
|
||||||
@ -838,6 +838,9 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func
|
|||||||
/** DATATABLE */
|
/** DATATABLE */
|
||||||
$routes->get('maquinas/tareas/datatable/(:alpha)/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_datatable/$1/$2', ['as' => 'viewMaquinistaMaquinaTareaDatatable']);
|
$routes->get('maquinas/tareas/datatable/(:alpha)/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_datatable/$1/$2', ['as' => 'viewMaquinistaMaquinaTareaDatatable']);
|
||||||
$routes->get('maquinas/tareas/aplazadas/datatable/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_aplazada_datatable/$1', ['as' => 'viewMaquinistaMaquinaTareaAplazadaDatatable']);
|
$routes->get('maquinas/tareas/aplazadas/datatable/(:num)', 'Ordentrabajo::maquinista_maquina_tareas_aplazada_datatable/$1', ['as' => 'viewMaquinistaMaquinaTareaAplazadaDatatable']);
|
||||||
|
|
||||||
|
/** POST */
|
||||||
|
$routes->post('maquinas/tareas/printLabels', 'Ordentrabajo::printPackagingLabels');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,6 +11,8 @@ use App\Models\OrdenTrabajo\OrdenTrabajoTarea;
|
|||||||
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
use App\Models\OrdenTrabajo\OrdenTrabajoUser;
|
||||||
use App\Models\Presupuestos\PresupuestoModel;
|
use App\Models\Presupuestos\PresupuestoModel;
|
||||||
use App\Models\Usuarios\UserModel;
|
use App\Models\Usuarios\UserModel;
|
||||||
|
use App\Services\EtiquetasTitulosService;
|
||||||
|
use App\Services\ImpresoraEtiquetaService;
|
||||||
use App\Services\ProductionService;
|
use App\Services\ProductionService;
|
||||||
use CodeIgniter\Files\File;
|
use CodeIgniter\Files\File;
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
@ -22,6 +24,7 @@ use Exception;
|
|||||||
use Hermawan\DataTables\DataTable;
|
use Hermawan\DataTables\DataTable;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
|
||||||
class Ordentrabajo extends BaseController
|
class Ordentrabajo extends BaseController
|
||||||
{
|
{
|
||||||
protected $format = 'json';
|
protected $format = 'json';
|
||||||
@ -627,10 +630,19 @@ class Ordentrabajo extends BaseController
|
|||||||
|
|
||||||
public function maquinista_maquina_tarea_view(int $orden_trabajo_tarea_id)
|
public function maquinista_maquina_tarea_view(int $orden_trabajo_tarea_id)
|
||||||
{
|
{
|
||||||
|
$modelImpresoras = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||||
|
$impresoras = $modelImpresoras->select('id, name')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->where('tipo', 1)
|
||||||
|
->orderBy('name', 'asc')
|
||||||
|
->findAll();
|
||||||
|
$impresoras = array_map(fn($impresora) => $impresora->toArray(), $impresoras);
|
||||||
$otTareaEntity = $this->otTarea->find($orden_trabajo_tarea_id);
|
$otTareaEntity = $this->otTarea->find($orden_trabajo_tarea_id);
|
||||||
$this->viewData['ot_tarea'] = $otTareaEntity;
|
$this->viewData['ot_tarea'] = $otTareaEntity;
|
||||||
$this->viewData['ot'] = $otTareaEntity->orden_trabajo();
|
$this->viewData['ot'] = $otTareaEntity->orden_trabajo();
|
||||||
$this->viewData['presupuesto'] = $this->viewData['ot']->presupuesto();
|
$this->viewData['presupuesto'] = $this->viewData['ot']->presupuesto();
|
||||||
|
|
||||||
|
$this->viewData['impresoras'] = $impresoras;
|
||||||
$this->viewData['breadcrumb'] = [
|
$this->viewData['breadcrumb'] = [
|
||||||
['title' => lang("Produccion.maquinista.maquinas"), 'route' => route_to("viewProduccionMaquinistaMaquinas"), 'active' => false],
|
['title' => lang("Produccion.maquinista.maquinas"), 'route' => route_to("viewProduccionMaquinistaMaquinas"), 'active' => false],
|
||||||
['title' => $otTareaEntity->maquina_actual()->nombre, 'route' => route_to("viewProduccionMaquinaTareasList", $otTareaEntity?->maquina_actual()?->id), 'active' => true],
|
['title' => $otTareaEntity->maquina_actual()->nombre, 'route' => route_to("viewProduccionMaquinaTareasList", $otTareaEntity?->maquina_actual()?->id), 'active' => true],
|
||||||
@ -919,4 +931,36 @@ class Ordentrabajo extends BaseController
|
|||||||
return $this->response->setJSON($responseData);
|
return $this->response->setJSON($responseData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function printPackagingLabels(){
|
||||||
|
|
||||||
|
$ot_id = $this->request->getPost('ot_id') ?? null;
|
||||||
|
$unidades_caja = $this->request->getPost('unidades_caja') ?? null;
|
||||||
|
$impresora_id = $this->request->getPost('impresora_id') ?? null;
|
||||||
|
|
||||||
|
if ($ot_id == null || $impresora_id == null) {
|
||||||
|
return [
|
||||||
|
'status' => false,
|
||||||
|
'message' => lang('Logistica.errors.errorMissingData')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||||
|
$impresora = $modelImpresora->select('id, name, ip, port, user, pass')
|
||||||
|
->where('deleted_at', null)
|
||||||
|
->where('id', $impresora_id)
|
||||||
|
->orderBy('name', 'asc')
|
||||||
|
->first();
|
||||||
|
if ($impresora == null) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Impresora no válida'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$printerService = new ImpresoraEtiquetaService();
|
||||||
|
$result = $printerService->generateEtiquetasEmbalaje($ot_id, $unidades_caja, $impresora);
|
||||||
|
|
||||||
|
return $this->response->setJSON($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,6 +134,87 @@ class ImpresoraEtiquetaService extends BaseService
|
|||||||
return $xml->saveXML();
|
return $xml->saveXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateEtiquetasEmbalaje($ot_id, $ejemplares_caja, $printer)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"printer" => $printer->name,
|
||||||
|
"header" => [
|
||||||
|
"_FORMAT" => "E:PEDIDO.ZPL",
|
||||||
|
"_QUANTITY" => 1,
|
||||||
|
"_PRINBTERNAME" => $printer->name,
|
||||||
|
"_JOBNAME" => "LBL101"
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$ot_model = model('App\Models\OrdenTrabajo\OrdenTrabajoModel');
|
||||||
|
$datos = $ot_model->select('
|
||||||
|
ordenes_trabajo.total_tirada as unidades,
|
||||||
|
clientes.nombre as cliente,
|
||||||
|
presupuestos.titulo as titulo,
|
||||||
|
presupuestos.isbn as isbn,
|
||||||
|
presupuestos.referencia_cliente as referencia_cliente,
|
||||||
|
pedidos.id as pedido
|
||||||
|
')
|
||||||
|
->join('pedidos', 'ordenes_trabajo.pedido_id = pedidos.id')
|
||||||
|
->join('pedidos_linea', 'pedidos.id = pedidos_linea.pedido_id')
|
||||||
|
->join('presupuestos', 'pedidos_linea.presupuesto_id = presupuestos.id')
|
||||||
|
->join('clientes', 'presupuestos.cliente_id = clientes.id')
|
||||||
|
->where('ordenes_trabajo.id', $ot_id)
|
||||||
|
->first();
|
||||||
|
$cajas = ceil($datos->unidades / $ejemplares_caja);
|
||||||
|
$cantidad = 0;
|
||||||
|
|
||||||
|
for( $i = 1; $i <= $cajas; $i++) {
|
||||||
|
$data["labels"][] = [
|
||||||
|
"cliente" => $datos->cliente,
|
||||||
|
"titulo" => $datos->titulo,
|
||||||
|
"cantidad" => $cantidad + $ejemplares_caja <= $datos->unidades ? $ejemplares_caja : $datos->unidades-$cantidad,
|
||||||
|
"tirada" => $datos->unidades,
|
||||||
|
"cajas" => $cajas,
|
||||||
|
"ean" => str_replace("-", "", $datos->isbn),
|
||||||
|
"nombre" => null,
|
||||||
|
"direccion" => null,
|
||||||
|
"notas" => "",
|
||||||
|
"refcliente" => $datos->referencia_cliente,
|
||||||
|
"npedido" => $datos->pedido
|
||||||
|
];
|
||||||
|
|
||||||
|
$cantidad += $ejemplares_caja;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function sendToImpresoraEtiqueta(string $name, string $content, ImpresoraEtiquetaEntity $impresoraEtiqueta): bool
|
public function sendToImpresoraEtiqueta(string $name, string $content, ImpresoraEtiquetaEntity $impresoraEtiqueta): bool
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="mt-lg-4 mt-lg-2 mb-lg-4 mb-2 pt-1 w-100">
|
<div class="mt-lg-4 mt-lg-2 mb-lg-4 mb-2 pt-1 w-100">
|
||||||
<p class="mb-0">OT ID</p>
|
<p class="mb-0">OT ID</p>
|
||||||
<h4 class="mb-0"><?= $ot->id ?></h4>
|
<h4 id="otId" class="mb-0"><?= $ot->id ?></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-lg-4 mt-lg-2 mb-lg-4 mb-2 pt-1 w-100">
|
<div class="mt-lg-4 mt-lg-2 mb-lg-4 mb-2 pt-1 w-100">
|
||||||
<p class="mb-0">Clicks presupuesto</p>
|
<p class="mb-0">Clicks presupuesto</p>
|
||||||
|
|||||||
@ -6,6 +6,9 @@
|
|||||||
<?= $this->section('content'); ?>
|
<?= $this->section('content'); ?>
|
||||||
<!--Content Body-->
|
<!--Content Body-->
|
||||||
<div class="row" id="viewMaquinistaMaquinaTarea" data-id="<?= $ot_tarea->id ?>">
|
<div class="row" id="viewMaquinistaMaquinaTarea" data-id="<?= $ot_tarea->id ?>">
|
||||||
|
|
||||||
|
<input type="hidden" id="impresoras" value='<?= json_encode($impresoras, JSON_HEX_APOS | JSON_HEX_QUOT) ?>'>
|
||||||
|
|
||||||
<div class="nav-align-top">
|
<div class="nav-align-top">
|
||||||
<ul class="nav nav-pills mb-4 nav-fill" role="tablist">
|
<ul class="nav nav-pills mb-4 nav-fill" role="tablist">
|
||||||
<li class="nav-item mb-1 mb-sm-0">
|
<li class="nav-item mb-1 mb-sm-0">
|
||||||
@ -43,7 +46,7 @@
|
|||||||
<div class="row mb-2 h-100 d-flex flex-wrap">
|
<div class="row mb-2 h-100 d-flex flex-wrap">
|
||||||
<?php if ($ot_tarea?->maquina_actual()?->etiqueta_envio): ?>
|
<?php if ($ot_tarea?->maquina_actual()?->etiqueta_envio): ?>
|
||||||
<div class="col-md-12 d-flex justify-content-end mb-2">
|
<div class="col-md-12 d-flex justify-content-end mb-2">
|
||||||
<button class="btn-primary btn d-flex justify-content-evenly gap-2" data-id="<?=$ot_tarea?->maquina_actual()->id?>"><span class="ti ti-barcode ti-lg"></span><?= lang('Produccion.print_label') ?></button>
|
<button id="btn-print-labels" class="btn-primary btn d-flex justify-content-evenly gap-2" data-id="<?=$ot_tarea?->maquina_actual()->id?>"><span class="ti ti-barcode ti-lg"></span><?= lang('Produccion.print_label') ?></button>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="col-md-6 tarea-card-info-block">
|
<div class="col-md-6 tarea-card-info-block">
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class MaquinistaTareaView {
|
|||||||
this.actionButtons = this.item.find('.action-btn')
|
this.actionButtons = this.item.find('.action-btn')
|
||||||
this.tareaCardClass = '.tarea-card-action-block'
|
this.tareaCardClass = '.tarea-card-action-block'
|
||||||
this.inputClick = $('.ot-tarea-click')
|
this.inputClick = $('.ot-tarea-click')
|
||||||
|
this.btnPrintLabels = this.item.find('#btn-print-labels')
|
||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
this.actionButtons.on('click', this.eventActionButton.bind(this))
|
this.actionButtons.on('click', this.eventActionButton.bind(this))
|
||||||
@ -20,6 +21,7 @@ class MaquinistaTareaView {
|
|||||||
this.btnDeleteProgress.on('click', this.handleDeleteTareaProgress.bind(this))
|
this.btnDeleteProgress.on('click', this.handleDeleteTareaProgress.bind(this))
|
||||||
this.handleGetTareaProgress();
|
this.handleGetTareaProgress();
|
||||||
this.inputClick.on('input', this.handleUpdateClickInput.bind(this))
|
this.inputClick.on('input', this.handleUpdateClickInput.bind(this))
|
||||||
|
this.btnPrintLabels.on('click', this.handlePrintLabels.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
eventActionButton(event) {
|
eventActionButton(event) {
|
||||||
@ -53,8 +55,8 @@ class MaquinistaTareaView {
|
|||||||
}
|
}
|
||||||
disableButtons() {
|
disableButtons() {
|
||||||
this.actionButtons.attr('disabled', 'disabled')
|
this.actionButtons.attr('disabled', 'disabled')
|
||||||
this.btnDelay.attr('disabled','disabled')
|
this.btnDelay.attr('disabled', 'disabled')
|
||||||
this.btnDeleteProgress.attr('disabled','disabled')
|
this.btnDeleteProgress.attr('disabled', 'disabled')
|
||||||
}
|
}
|
||||||
enableButtons() {
|
enableButtons() {
|
||||||
this.actionButtons.removeAttr('disabled')
|
this.actionButtons.removeAttr('disabled')
|
||||||
@ -127,7 +129,7 @@ class MaquinistaTareaView {
|
|||||||
let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado
|
let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado
|
||||||
console.log("Last status :", lastStatus)
|
console.log("Last status :", lastStatus)
|
||||||
this.showBasedOnStatus(lastStatus)
|
this.showBasedOnStatus(lastStatus)
|
||||||
}else{
|
} else {
|
||||||
this.showBasedOnStatus('P')
|
this.showBasedOnStatus('P')
|
||||||
}
|
}
|
||||||
this.item.find('#tiempo-real-info').html(response.tiempo_trabajado ?? "00:00")
|
this.item.find('#tiempo-real-info').html(response.tiempo_trabajado ?? "00:00")
|
||||||
@ -148,14 +150,14 @@ class MaquinistaTareaView {
|
|||||||
this.handleUpdateTareaProgressError.bind(this),
|
this.handleUpdateTareaProgressError.bind(this),
|
||||||
)
|
)
|
||||||
if (this.tareaId) {
|
if (this.tareaId) {
|
||||||
if(status == "F"){
|
if (status == "F") {
|
||||||
alertConfirmAction('La tarea se marcará como finalizada')
|
alertConfirmAction('La tarea se marcará como finalizada')
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
ajax.post();
|
ajax.post();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
} else {
|
||||||
ajax.post();
|
ajax.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,6 +226,80 @@ class MaquinistaTareaView {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePrintLabels() {
|
||||||
|
|
||||||
|
const impresoras = JSON.parse($('#impresoras').val());
|
||||||
|
|
||||||
|
let options = '';
|
||||||
|
impresoras.forEach(p => {
|
||||||
|
options += `<option value="${p.id}">${p.name}</option>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Imprimir etiquetas',
|
||||||
|
html: `
|
||||||
|
<div class="mb-3 text-start">
|
||||||
|
<label for="swal-impresora" class="form-label">Impresora</label>
|
||||||
|
<select id="swal-impresora" class="form-control">
|
||||||
|
${options}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 text-start">
|
||||||
|
<label for="swal-unidades" class="form-label">Unidades por caja</label>
|
||||||
|
<input type="number" id="swal-unidades" class="form-control" min="1" value="${$("#tirada-info").html()}" />
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Aceptar',
|
||||||
|
cancelButtonText: 'Cancelar',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
cancelButton: 'btn btn-secondary'
|
||||||
|
},
|
||||||
|
buttonsStyling: false,
|
||||||
|
preConfirm: () => {
|
||||||
|
const impresora = $('#swal-impresora').val();
|
||||||
|
const unidades = parseInt($('#swal-unidades').val(), 10);
|
||||||
|
|
||||||
|
if (!impresora || isNaN(unidades) || unidades <= 0) {
|
||||||
|
Swal.showValidationMessage('Debe seleccionar una impresora y un número válido de unidades.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { impresora, unidades };
|
||||||
|
}
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
|
||||||
|
$.post('/produccion/ordentrabajo/maquinista/maquinas/tareas/printLabels', {
|
||||||
|
impresora_id: result.value.impresora,
|
||||||
|
unidades_caja: result.value.unidades,
|
||||||
|
ot_id: $('#otId').html(),
|
||||||
|
}, function (response) {
|
||||||
|
if (response.status) {
|
||||||
|
popSuccessAlert(response.message);
|
||||||
|
if(response.data) {
|
||||||
|
// show xml in new tab
|
||||||
|
const blob = new Blob([response.data], { type: 'application/xml' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const newTab = window.open(url, '_blank');
|
||||||
|
if (newTab) {
|
||||||
|
newTab.onload = function () {
|
||||||
|
// Revoke the object URL after the new tab has loaded
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
popErrorAlert('Error abriendo la pestaña');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
popErrorAlert(response.error)
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user