mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into feat/update-ot-flow
This commit is contained in:
@ -450,6 +450,76 @@ class ImportadorBubok extends BaseResourceController
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
||||
// Descarga y subida de archivos al SFTP
|
||||
$presupuestoFicheroModel = model('App\Models\Presupuestos\PresupuestoFicheroModel');
|
||||
$ftp = new \App\Libraries\SafekatFtpClient();
|
||||
|
||||
$archivoUrls = [
|
||||
'cover' => $producto->cover->file ?? null,
|
||||
'body' => $producto->body->file ?? null,
|
||||
];
|
||||
|
||||
foreach ($archivoUrls as $tipo => $url) {
|
||||
if (!$url)
|
||||
continue;
|
||||
|
||||
try {
|
||||
$contenido = @file_get_contents($url); // silenciar errores de PHP
|
||||
|
||||
if ($contenido === false || strlen($contenido) === 0) {
|
||||
// No se pudo descargar el archivo: generar archivo de error para FTP
|
||||
$errorMessage = "ERROR: No se pudo descargar el archivo remoto para $tipo desde la URL: $url";
|
||||
|
||||
$remoteDir = $ftp->getPresupuestoRemotePath($response['sk_id']); // crea esta función si no existe
|
||||
$remoteErrorFile = $remoteDir . '/ERROR_' . strtoupper($tipo) . '.txt';
|
||||
|
||||
// Crear archivo temporal con el mensaje de error
|
||||
$tempErrorFile = WRITEPATH . 'uploads/presupuestos/ERROR_' . $tipo . '.txt';
|
||||
file_put_contents($tempErrorFile, $errorMessage);
|
||||
|
||||
if (!$ftp->is_dir($remoteDir)) {
|
||||
$ftp->mkdir($remoteDir, recursive: true);
|
||||
}
|
||||
|
||||
$ftp->put($remoteErrorFile, $tempErrorFile, $ftp::SOURCE_LOCAL_FILE);
|
||||
|
||||
continue; // no procesar este archivo
|
||||
}
|
||||
|
||||
// ✅ Procesar normalmente si la descarga tuvo éxito
|
||||
$nombreOriginal = basename(parse_url($url, PHP_URL_PATH));
|
||||
$extension = pathinfo($nombreOriginal, PATHINFO_EXTENSION);
|
||||
|
||||
$nombreLimpio = $presupuestoFicheroModel->saveFileInBBDD(
|
||||
$response['sk_id'],
|
||||
$nombreOriginal,
|
||||
$extension,
|
||||
auth()->id()
|
||||
);
|
||||
|
||||
if (is_null($nombreLimpio))
|
||||
continue;
|
||||
|
||||
$rutaLocal = WRITEPATH . 'uploads/presupuestos/';
|
||||
if (!is_dir($rutaLocal)) {
|
||||
mkdir($rutaLocal, 0777, true);
|
||||
}
|
||||
|
||||
file_put_contents($rutaLocal . $nombreLimpio, $contenido);
|
||||
} catch (\Throwable $e) {
|
||||
//log_message('error', 'Error inesperado en descarga de archivo remoto: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Subir al FTP después de guardar localmente
|
||||
try {
|
||||
$ftp->uploadFilePresupuesto($response['sk_id']);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'Error subiendo archivos al FTP: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 200,
|
||||
'data' => [
|
||||
@ -458,6 +528,7 @@ class ImportadorBubok extends BaseResourceController
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->respond([
|
||||
'status' => 500,
|
||||
|
||||
@ -163,10 +163,10 @@ class EtiquetasTitulosController extends BaseController
|
||||
|
||||
|
||||
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||
$impresoras = $modelImpresora->select('id, name')
|
||||
$impresoras = $modelImpresora->select('id, name, description')
|
||||
->where('deleted_at', null)
|
||||
->where('tipo', 1)
|
||||
->orderBy('name', 'desc')
|
||||
->orderBy('name', 'asc')
|
||||
->findAll();
|
||||
$etiquetaEntity->impresoras = $impresoras;
|
||||
|
||||
@ -440,7 +440,7 @@ class EtiquetasTitulosController extends BaseController
|
||||
$impresora_id = $this->request->getPost('impresora_id') ?? null;
|
||||
|
||||
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||
$impresora = $modelImpresora->select('id, name, ip, port, user, pass')
|
||||
$impresora = $modelImpresora->select('id, name, description, ip, port, user, pass')
|
||||
->where('deleted_at', null)
|
||||
->where('id', $impresora_id)
|
||||
->orderBy('name', 'asc')
|
||||
|
||||
@ -98,7 +98,8 @@ class LogisticaController extends BaseController
|
||||
return view(static::$viewPath . 'viewImpresionEtiquetas', $viewData);
|
||||
}
|
||||
|
||||
public function listAlbaranes(){
|
||||
public function listAlbaranes()
|
||||
{
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'boxTitle' => lang('Albaran.albaranes'),
|
||||
@ -117,7 +118,7 @@ class LogisticaController extends BaseController
|
||||
|
||||
$tipo_envio = $this->request->getGet('tipo_envio') ?? 'estandar';
|
||||
|
||||
if($tipo_envio == 'ferro_prototipo'){
|
||||
if ($tipo_envio == 'ferro_prototipo') {
|
||||
$query = LogisticaService::findForNewEnvioFerro();
|
||||
} else {
|
||||
$query = LogisticaService::findForNewEnvio();
|
||||
@ -132,22 +133,25 @@ class LogisticaController extends BaseController
|
||||
|
||||
$result = $query->orderBy("name", "asc")->get()->getResultObject();
|
||||
|
||||
$query = model('App\Models\Logistica\EnvioModel')->db->getLastQuery();
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function selectDireccionForEnvio(){
|
||||
public function selectDireccionForEnvio()
|
||||
{
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$ot = $this->request->getGet('ot_id');
|
||||
if($ot == null || $ot == 0){
|
||||
if ($ot == null || $ot == 0) {
|
||||
return [];
|
||||
}
|
||||
$searchVal = $this->request->getGet("q") ?? "";
|
||||
$result = LogisticaService::findDireccionesNewEnvio($ot, $searchVal);
|
||||
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
@ -185,12 +189,12 @@ class LogisticaController extends BaseController
|
||||
public function imprimirEtiquetas()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$envio_id = $this->request->getPost('envio_id');
|
||||
$envio_id = $this->request->getPost('envio_id');
|
||||
$ids = $this->request->getPost('envio_lineas');
|
||||
$cajas = $this->request->getPost('cajas');
|
||||
$printer_id = $this->request->getPost('printer_id');
|
||||
|
||||
if($cajas == null || $cajas == 0){
|
||||
if ($cajas == null || $cajas == 0) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Cajas no válidas'
|
||||
@ -202,7 +206,7 @@ class LogisticaController extends BaseController
|
||||
->join('clientes', 'clientes.id = envios.cliente_id', 'left')
|
||||
->where('envios.id', $envio_id)
|
||||
->first();
|
||||
if($envio == null){
|
||||
if ($envio == null) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Envio no válido'
|
||||
@ -213,7 +217,7 @@ class LogisticaController extends BaseController
|
||||
$lineas = $model->select('envios_lineas.*, presupuestos.titulo as titulo, presupuestos.referencia_cliente as referencia_cliente')
|
||||
->join('presupuestos', 'presupuestos.id = envios_lineas.presupuesto_id', 'left')
|
||||
->whereIn('envios_lineas.id', $ids)->findAll();
|
||||
if($lineas == null){
|
||||
if ($lineas == null) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Lineas no válidas'
|
||||
@ -221,12 +225,12 @@ class LogisticaController extends BaseController
|
||||
}
|
||||
|
||||
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||
$impresora = $modelImpresora->select('id, name, ip, port, user, pass')
|
||||
$impresora = $modelImpresora->select('id, name, description, ip, port, user, pass')
|
||||
->where('deleted_at', null)
|
||||
->where('id', $printer_id)
|
||||
->orderBy('name', 'asc')
|
||||
->first();
|
||||
if($impresora == null){
|
||||
if ($impresora == null) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Impresora no válida'
|
||||
@ -330,22 +334,22 @@ class LogisticaController extends BaseController
|
||||
if (empty($envioEntity)) {
|
||||
return redirect()->to(base_url('logistica/selectEnvios/simple'))->with('error', lang('Logistica.errors.noEnvio'));
|
||||
}
|
||||
|
||||
|
||||
$modelProveedor = model('App\Models\Compras\ProveedorModel');
|
||||
$proveedor = $modelProveedor->select('id, nombre')
|
||||
->where('deleted_at', null)
|
||||
->where('id', $envioEntity->proveedor_id)
|
||||
->orderBy('nombre', 'asc')
|
||||
->first();
|
||||
if(!empty($proveedor)){
|
||||
if (!empty($proveedor)) {
|
||||
$envioEntity->proveedor_nombre = $proveedor->nombre;
|
||||
}
|
||||
|
||||
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||
$impresoras = $modelImpresora->select('id, name')
|
||||
$impresoras = $modelImpresora->select('id, name, description')
|
||||
->where('deleted_at', null)
|
||||
->where('tipo', 1)
|
||||
->orderBy('name', 'desc')
|
||||
->orderBy('name', 'asc')
|
||||
->findAll();
|
||||
$envioEntity->impresoras = $impresoras;
|
||||
|
||||
@ -384,7 +388,7 @@ class LogisticaController extends BaseController
|
||||
|
||||
$id = $this->request->getPost('id') ?? null;
|
||||
$finalizar_ots = $this->request->getPost('finalizar_ots') ?? false;
|
||||
|
||||
|
||||
$result = LogisticaService::finalizarEnvio($id, $finalizar_ots);
|
||||
return $this->response->setJSON($result);
|
||||
} else {
|
||||
@ -392,6 +396,17 @@ class LogisticaController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function ficharEmbalaje()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$ids = $this->request->getPost('ids') ?? [];
|
||||
$result = LogisticaService::ficharEmbalaje($ids);
|
||||
return $this->response->setJSON($result);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable_enviosEdit($idEnvio)
|
||||
{
|
||||
@ -406,6 +421,12 @@ class LogisticaController extends BaseController
|
||||
return '<input type="checkbox" class="form-check-input checkbox-linea-envio" name="row_selected[]" value="' . $q->id . '">';
|
||||
}
|
||||
)
|
||||
->edit(
|
||||
"ordenTrabajo",
|
||||
function ($row, $meta) {
|
||||
return '<a href="' . base_url('produccion/ordentrabajo/edit/' . $row->ordenTrabajo) . '" target="_blank">' . $row->ordenTrabajo . '</a>';
|
||||
}
|
||||
)
|
||||
->edit(
|
||||
"pedido",
|
||||
function ($row, $meta) {
|
||||
@ -420,17 +441,35 @@ class LogisticaController extends BaseController
|
||||
)->edit(
|
||||
"unidadesEnvio",
|
||||
function ($row, $meta) {
|
||||
if($row->finalizado == 1 || $row->tipo_envio == 'ferro_prototipo'){
|
||||
if ($row->finalizado == 1 || $row->tipo_envio == 'ferro_prototipo') {
|
||||
return $row->unidadesEnvio;
|
||||
}
|
||||
return '<input type="number" class="form-control input-lineas input-unidades text-center"
|
||||
data-id="'. $row->id.'" data-name="unidades_envio" value="' . $row->unidadesEnvio . '">';
|
||||
data-id="' . $row->id . '" data-name="unidades_envio" value="' . $row->unidadesEnvio . '">';
|
||||
}
|
||||
);
|
||||
|
||||
return $result->toJson(returnAsObject: true);
|
||||
}
|
||||
|
||||
public function datatable_proximosEnvios($envio_id = null)
|
||||
{
|
||||
$q = LogisticaService::findNextEnvios($envio_id);
|
||||
|
||||
$result = DataTable::of($q)
|
||||
->edit(
|
||||
"ot",
|
||||
function ($row, $meta) {
|
||||
return '<a href="' . base_url('produccion/ordentrabajo/edit/' . $row->ot) . '" target="_blank">' . $row->ot . '</a>';
|
||||
}
|
||||
);
|
||||
|
||||
$result = $result->toJson(returnAsObject: true);
|
||||
$query = model('App\Models\Logistica\EnvioModel')->db->getLastQuery();
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function setCajaLinea()
|
||||
{
|
||||
|
||||
@ -471,7 +510,7 @@ class LogisticaController extends BaseController
|
||||
$fieldName = $this->request->getPost('name');
|
||||
$fieldValue = $this->request->getPost('value');
|
||||
|
||||
if (!$id || !$fieldName || ($fieldName=='unidades_envio' && !$fieldValue)) {
|
||||
if (!$id || !$fieldName || ($fieldName == 'unidades_envio' && !$fieldValue)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Datos inválidos'
|
||||
@ -480,7 +519,7 @@ class LogisticaController extends BaseController
|
||||
|
||||
$model = model('App\Models\Logistica\EnvioLineaModel');
|
||||
$updated = $model->update($id, [
|
||||
"" . $fieldName => $fieldValue==""? null: $fieldValue,
|
||||
"" . $fieldName => $fieldValue == "" ? null : $fieldValue,
|
||||
]);
|
||||
|
||||
return $this->response->setJSON([
|
||||
@ -503,7 +542,7 @@ class LogisticaController extends BaseController
|
||||
|
||||
$model = model('App\Models\Logistica\EnvioModel');
|
||||
$updated = $model->update($id, [
|
||||
"codigo_seguimiento" => $fieldValue==""? null: $fieldValue,
|
||||
"codigo_seguimiento" => $fieldValue == "" ? null : $fieldValue,
|
||||
]);
|
||||
|
||||
return $this->response->setJSON([
|
||||
@ -526,7 +565,7 @@ class LogisticaController extends BaseController
|
||||
|
||||
$model = model('App\Models\Logistica\EnvioModel');
|
||||
$updated = $model->update($id, [
|
||||
"proveedor_id" => $fieldValue==""? null: $fieldValue,
|
||||
"proveedor_id" => $fieldValue == "" ? null : $fieldValue,
|
||||
]);
|
||||
|
||||
return $this->response->setJSON([
|
||||
|
||||
@ -951,7 +951,7 @@ class Ordentrabajo extends BaseController
|
||||
}
|
||||
|
||||
$modelImpresora = model('App\Models\Configuracion\ImpresoraEtiquetaModel');
|
||||
$impresora = $modelImpresora->select('id, name, ip, port, user, pass')
|
||||
$impresora = $modelImpresora->select('id, name, description, ip, port, user, pass')
|
||||
->where('deleted_at', null)
|
||||
->where('id', $impresora_id)
|
||||
->orderBy('name', 'asc')
|
||||
|
||||
Reference in New Issue
Block a user