diff --git a/ci4/app/Config/Routes/ScriptsRoutes.php b/ci4/app/Config/Routes/ScriptsRoutes.php
new file mode 100644
index 00000000..f7e994c9
--- /dev/null
+++ b/ci4/app/Config/Routes/ScriptsRoutes.php
@@ -0,0 +1,13 @@
+group('scripts', ['namespace' => 'App\Controllers\Scripts'], function ($routes) {
+
+ $routes->get('completar-identidades', 'UsersIntegrity::completarIdentidades');
+
+
+});
\ No newline at end of file
diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php
index ea45c3c7..7d6cf687 100755
--- a/ci4/app/Controllers/Facturacion/Facturas.php
+++ b/ci4/app/Controllers/Facturacion/Facturas.php
@@ -833,9 +833,18 @@ class Facturas extends \App\Controllers\BaseResourceController
if ((strpos($numero, "REC ") === 0)) {
$data['estado_pago'] = 'pagada';
+
}
$this->model->update($factura_id, $data);
+
+ if ((strpos($numero, "REC ") === 0)) {
+
+ $this->model->where('numero', $factura->factura_rectificada_id)->set([
+ 'factura_rectificativa_id' => $numero,
+ 'user_updated_id' => auth()->user()->id,
+ ])->update();
+ }
}
diff --git a/ci4/app/Controllers/Facturacion/FacturasLineas.php b/ci4/app/Controllers/Facturacion/FacturasLineas.php
index 0c12c403..386aa70b 100755
--- a/ci4/app/Controllers/Facturacion/FacturasLineas.php
+++ b/ci4/app/Controllers/Facturacion/FacturasLineas.php
@@ -92,7 +92,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
Field::inst('id'),
Field::inst('base'),
Field::inst('total_iva'),
- Field::inst('total'),
+ Field::inst('total')->set(Field::SET_BOTH),
Field::inst('cantidad')
->validator(
'Validate::numeric',
@@ -126,19 +126,6 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
'message' => lang('Facturas.validation.requerido')
)
),
- Field::inst('total')
- ->validator(
- 'Validate::numeric',
- array(
- 'message' => lang('Facturas.validation.numerico')
- )
- )
- ->validator(
- 'Validate::notEmpty',
- array(
- 'message' => lang('Facturas.validation.requerido')
- )
- ),
Field::inst('pedido_linea_impresion_id')
->setFormatter(function ($val, $data, $opts) {
return $val === '' ? null : $val;
@@ -157,7 +144,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
$values['total'],
$values['iva'],
$values['cantidad'],
- $values['old_cantidad'],
+ $values['old_cantidad'],
$values['base']
);
$editor
@@ -183,7 +170,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
$values['total'],
$values['iva'],
$values['cantidad'],
- $values['old_cantidad'],
+ $values['old_cantidad'],
$values['base']
);
$editor
@@ -256,14 +243,13 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
$values['base'] = $base;
$values['total_iva'] = $total_iva;
$values['total'] = $total;
- }
- else{
+ } else {
// se pasa la base y el iva
$total_iva = round($base_input * $iva / 100, 2);
$total = round($base_input + $total_iva, 2);
-
+
$values = [];
- $values['base'] = $base_input;
+ $values['base'] = (float) $base_input;
$values['total_iva'] = $total_iva;
$values['total'] = $total;
diff --git a/ci4/app/Controllers/Importadores/ImportadorBubok.php b/ci4/app/Controllers/Importadores/ImportadorBubok.php
index 39ca1535..33fcc4d5 100644
--- a/ci4/app/Controllers/Importadores/ImportadorBubok.php
+++ b/ci4/app/Controllers/Importadores/ImportadorBubok.php
@@ -371,7 +371,7 @@ class ImportadorBubok extends BaseResourceController
// confirmar y crear pedido y ot
$presupuestoModel->confirmarPresupuesto($response['sk_id']);
- PresupuestoService::crearPedido($response['sk_id']);
+ PresupuestoService::crearPedido($response['sk_id'],isImported:true);
if (!isset($response['sk_id'])) {
diff --git a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php
index ca13df60..d3797f3e 100644
--- a/ci4/app/Controllers/Importadores/ImportadorCatalogo.php
+++ b/ci4/app/Controllers/Importadores/ImportadorCatalogo.php
@@ -359,7 +359,7 @@ class ImportadorCatalogo extends BaseResourceController
// confirmar y crear pedido y ot
model('App\Models\Presupuestos\PresupuestoModel')->confirmarPresupuesto($response['data']['sk_id']);
- PresupuestoService::crearPedido($response['data']['sk_id']);
+ PresupuestoService::crearPedido($response['data']['sk_id'],isImported:true);
return $this->respond($response);
diff --git a/ci4/app/Controllers/Scripts/UsersIntegrity.php b/ci4/app/Controllers/Scripts/UsersIntegrity.php
new file mode 100644
index 00000000..5b7aa986
--- /dev/null
+++ b/ci4/app/Controllers/Scripts/UsersIntegrity.php
@@ -0,0 +1,76 @@
+where('deleted_at', null)
+ //->like('username', '@safekat.com')
+ ->findAll();
+
+ $resultados = [];
+
+ foreach ($usuarios as $usuario) {
+ $email = $usuario->username . "@safekat.com";
+
+ // 1. Verificar si el usuario ya tiene identidad tipo email_password
+ $tieneIdentidad = array_filter(
+ $usuario->getIdentities(),
+ fn($identity) => $identity->type === 'email_password'
+ );
+
+ if (!empty($tieneIdentidad)) {
+ $resultados[] = "✅ Ya tiene identidad: {$email}";
+ continue;
+ }
+
+ // 2. Verificar si ya existe una identidad globalmente con ese email
+ $db = db_connect();
+
+ $builder = $db->table('auth_identities');
+
+ $existeGlobal = $builder
+ ->where('type', 'email_password')
+ ->where('secret', $email)
+ ->get()
+ ->getFirstRow();
+
+ if ($existeGlobal) {
+ $resultados[] = "⚠️ Email ya registrado en otra identidad: {$email}";
+ continue;
+ }
+
+ // 3. Crear y guardar identidad
+ try {
+ $identity = $usuario->createEmailIdentity([
+ 'email' => $email,
+ 'password' => 'Temporal123!', // reemplazar por valor real si lo tenés
+ ]);
+
+ //$userModel->saveEmailIdentity($identity);
+
+ $resultados[] = "➕ Identidad creada: {$email}";
+ } catch (\Throwable $e) {
+ $resultados[] = "❌ Error con {$email}: " . $e->getMessage();
+ }
+ }
+
+ return $this->response->setJSON([
+ 'status' => 'completado',
+ 'procesados' => count($usuarios),
+ 'resultados' => $resultados,
+ ]);
+ }
+}
diff --git a/ci4/app/Models/Facturas/FacturaModel.php b/ci4/app/Models/Facturas/FacturaModel.php
index 7c2c8142..1cfbddb0 100755
--- a/ci4/app/Models/Facturas/FacturaModel.php
+++ b/ci4/app/Models/Facturas/FacturaModel.php
@@ -27,9 +27,9 @@ class FacturaModel extends \App\Models\BaseModel
];
const SORTABLE_PEDIDOS = [
- 1 => "t1.numero",
- 2 => "t2.nombre",
- 3 => "t4.cantidad",
+ 1 => "t1.id",
+ 2 => "t1.numero",
+ 3 => "t4.ejemplares",
4 => "t2.nombre",
5 => "t1.estado",
6 => "t1.fecha_factura_at",
@@ -129,7 +129,7 @@ class FacturaModel extends \App\Models\BaseModel
$builder->join("clientes t2", "t2.id = t1.cliente_id", "left");
$builder->join("facturas_pagos t3", "t3.factura_id = t1.id", "left");
$builder->join("formas_pago t4", "t3.forma_pago_id = t4.id", "left");
-
+
$builder->where("t1.deleted_at", null);
if (auth()->user()->inGroup("cliente-admin") || auth()->user()->inGroup("cliente-editor")) {
@@ -140,7 +140,7 @@ class FacturaModel extends \App\Models\BaseModel
$builder->where("t1.cliente_id", $cliente_id);
}
- $builder->groupBy("t1.id");
+ $builder->groupBy("t1.id");
//$query = $builder->getCompiledSelect();
return $builder;
}
@@ -166,9 +166,10 @@ class FacturaModel extends \App\Models\BaseModel
return !empty($result);
}
- public function getSumatoriosFacturacionCliente($cliente_id = -1){
+ public function getSumatoriosFacturacionCliente($cliente_id = -1)
+ {
- if($cliente_id == -1){
+ if ($cliente_id == -1) {
return [
'total_facturacion' => 0,
'total_pendiente' => 0
@@ -183,7 +184,7 @@ class FacturaModel extends \App\Models\BaseModel
->where('f.estado', 'validada')
->get()
->getResultObject();
- $result['total_facturacion'] =
+ $result['total_facturacion'] =
round(floatval(($data && $data[0]->total != null) ? $data[0]->total : 0), 2);
$data = $this->db->table('facturas f')
@@ -253,7 +254,17 @@ class FacturaModel extends \App\Models\BaseModel
$builder->join("pedidos t6", "t5.pedido_id = t6.id", "left");
$builder->where("t1.deleted_at IS NULL");
- $builder->where("t6.id", $pedido_id);
+ $builder->groupStart()
+ ->where("t6.id", $pedido_id)
+ ->orWhere("t1.factura_rectificada_id IN (
+ SELECT f.numero
+ FROM facturas f
+ JOIN facturas_pedidos_lineas fpl ON f.id = fpl.factura_id
+ JOIN pedidos_linea pl ON fpl.pedido_linea_id = pl.id
+ JOIN pedidos p ON pl.pedido_id = p.id
+ WHERE p.id = {$pedido_id}
+ )")
+ ->groupEnd();
$builder->groupBy("t1.id"); // Agrupa por id de la factura
diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php
index a6a80356..687dfc2a 100755
--- a/ci4/app/Services/PresupuestoService.php
+++ b/ci4/app/Services/PresupuestoService.php
@@ -1867,7 +1867,7 @@ class PresupuestoService extends BaseService
- public static function crearPedido($presupuesto_id)
+ public static function crearPedido($presupuesto_id,?bool $isImported = false)
{
$model_pedido = model('App\Models\Pedidos\PedidoModel');
$model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel');
@@ -1911,7 +1911,7 @@ class PresupuestoService extends BaseService
$serviceProduction->setPedido($pedido);
if (!$pedido->orden_trabajo()) {
- $r = $serviceProduction->createOrdenTrabajo(true);
+ $r = $serviceProduction->createOrdenTrabajo($isImported);
$modelPedido->set(['estado' => 'produccion'])->where('id', $pedido_id)->update();
}
}
diff --git a/ci4/app/Views/themes/vuexy/components/tables/ot_table.php b/ci4/app/Views/themes/vuexy/components/tables/ot_table.php
index ad280f80..c42bccec 100755
--- a/ci4/app/Views/themes/vuexy/components/tables/ot_table.php
+++ b/ci4/app/Views/themes/vuexy/components/tables/ot_table.php
@@ -4,7 +4,7 @@
+
- = lang('Produccion.datatable.ot_id') ?>
+ = lang('Produccion.datatable.ot_id') ?>
= lang('Produccion.datatable.pedido_id') ?>
= lang('Produccion.datatable.fecha_encuadernacion') ?>
= lang('Produccion.datatable.cliente') ?>
@@ -16,6 +16,20 @@
= lang('Produccion.datatable.progreso') ?>
= lang('Basic.global.Action') ?>
+
+
+
+
+
+
+
+
+
+
+
+
+