mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Corregidos bugs y homegeneizado
This commit is contained in:
@ -3,6 +3,7 @@ namespace App\Controllers\Importadores;
|
||||
|
||||
use App\Controllers\BaseResourceController;
|
||||
use App\Controllers\Presupuestos\Presupuestocliente;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Services\PresupuestoService;
|
||||
|
||||
class ImportadorBubok extends BaseResourceController
|
||||
@ -50,6 +51,73 @@ class ImportadorBubok extends BaseResourceController
|
||||
return view(static::$viewPath . 'viewImportadorBubokTool', $viewData);
|
||||
}
|
||||
|
||||
public function validarFila()
|
||||
{
|
||||
$json = $this->request->getJSON();
|
||||
|
||||
if (!$json || empty($json->producto) || empty($json->pedido)) {
|
||||
return $this->response->setJSON([
|
||||
'apto' => false,
|
||||
'reason' => 'Datos incompletos'
|
||||
]);
|
||||
}
|
||||
|
||||
$producto = $json->producto;
|
||||
$pedido = $json->pedido;
|
||||
|
||||
// Validar existencia de ID de producto
|
||||
if (empty($producto->id)) {
|
||||
return $this->response->setJSON([
|
||||
'apto' => false,
|
||||
'reason' => 'ID de producto no proporcionado'
|
||||
]);
|
||||
}
|
||||
|
||||
$refCliente = $pedido->orderNumber . '-' . $producto->id;
|
||||
|
||||
// Validar formato Ref. Cliente
|
||||
if (strpos($refCliente, '-') === false || strlen($refCliente) < 5) {
|
||||
return $this->response->setJSON([
|
||||
'apto' => false,
|
||||
'reason' => 'Ref. cliente inválido'
|
||||
]);
|
||||
}
|
||||
|
||||
// 1. Verificar si ya fue importado
|
||||
$presupuestoModel = new PresupuestoModel();
|
||||
$yaExiste = $presupuestoModel->where('referencia_cliente', $refCliente)->first();
|
||||
|
||||
if ($yaExiste) {
|
||||
return $this->response->setJSON([
|
||||
'apto' => false,
|
||||
'reason' => 'Referencia ya importada'
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Validación básica del producto (puedes expandir con más reglas si lo necesitas)
|
||||
$errores = [];
|
||||
|
||||
if (empty($producto->title))
|
||||
$errores[] = 'Falta título';
|
||||
if (empty($producto->body->pages))
|
||||
$errores[] = 'Faltan páginas';
|
||||
if (empty($producto->amount))
|
||||
$errores[] = 'Falta tirada';
|
||||
|
||||
if (!empty($errores)) {
|
||||
return $this->response->setJSON([
|
||||
'apto' => false,
|
||||
'reason' => implode(', ', $errores)
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. Producto considerado apto
|
||||
return $this->response->setJSON([
|
||||
'apto' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function importarFila()
|
||||
{
|
||||
@ -83,7 +151,7 @@ class ImportadorBubok extends BaseResourceController
|
||||
'message' => 'Número de orden o ID del producto no reconocidos.'
|
||||
]);
|
||||
}
|
||||
$refCliente = "$orderNumber - $productId";
|
||||
$refCliente = "$orderNumber-$productId";
|
||||
|
||||
// Titulo
|
||||
$titulo = $producto->title ?? null;
|
||||
@ -331,12 +399,12 @@ class ImportadorBubok extends BaseResourceController
|
||||
'ivaReducido' => 1,
|
||||
];
|
||||
|
||||
return $this->respond([
|
||||
/*return $this->respond([
|
||||
'status' => 400,
|
||||
'message' => $dataToImport,
|
||||
'interiorTipo' => $interiorTipo,
|
||||
'isColor' => $isColor
|
||||
]);
|
||||
]);*/
|
||||
|
||||
// 5. Guardar
|
||||
try {
|
||||
@ -368,11 +436,11 @@ class ImportadorBubok extends BaseResourceController
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// confirmar y crear pedido y ot
|
||||
$presupuestoModel->confirmarPresupuesto($response['sk_id']);
|
||||
PresupuestoService::crearPedido($response['sk_id'],isImported:true);
|
||||
|
||||
PresupuestoService::crearPedido($response['sk_id'], isImported: true);
|
||||
|
||||
|
||||
if (!isset($response['sk_id'])) {
|
||||
return $this->respond([
|
||||
|
||||
Reference in New Issue
Block a user