Carpeta models
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../database/database.php';
|
||||
|
||||
class configuracionModel {
|
||||
|
||||
private PDO $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = Database::getConnection();
|
||||
}
|
||||
|
||||
// OBTENER CONFIGRACIÓN
|
||||
|
||||
public function obtenerConfiguracion() {
|
||||
|
||||
$sql = "SELECT nombre, direccion, ciudad, codigo_postal, provincia, telefono, email, cond_iva, cuit, iva, inicio_act,
|
||||
hora_apertura_maniana, hora_cierre_maniana, hora_apertura_tarde, hora_cierre_tarde, mail_automatico, logo_ruta, cargo_cancelacion_servicio,
|
||||
email_emisor, contrasenia_emisor
|
||||
FROM configuracion WHERE id = 1";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// ACTUALIZAR CONFIGURACIÓN
|
||||
|
||||
public function actualizarConfiguracion(array $datosEmpresa): bool {
|
||||
|
||||
$sql = "UPDATE configuracion
|
||||
SET nombre = :nombre,
|
||||
direccion = :direccion,
|
||||
ciudad = :ciudad,
|
||||
codigo_postal = :codigo_postal,
|
||||
provincia = :provincia,
|
||||
telefono = :telefono,
|
||||
email = :email,
|
||||
cond_iva = :cond_iva,
|
||||
cuit = :cuit,
|
||||
iva = :iva,
|
||||
hora_apertura_maniana = :hora_apertura_maniana,
|
||||
hora_cierre_maniana = :hora_cierre_maniana,
|
||||
hora_apertura_tarde = :hora_apertura_tarde,
|
||||
hora_cierre_tarde = :hora_cierre_tarde,
|
||||
mail_automatico = :mail_automatico,
|
||||
cargo_cancelacion_servicio = :cargo_cancelacion_servicio,
|
||||
email_emisor = :email_emisor,
|
||||
contrasenia_emisor = :contrasenia_emisor
|
||||
WHERE id = 1";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
return (bool) $stmt->execute([
|
||||
'nombre' => $datosEmpresa['nombre'],
|
||||
'direccion' => $datosEmpresa['direccion'],
|
||||
'ciudad' => $datosEmpresa['ciudad'],
|
||||
'codigo_postal' => $datosEmpresa['codigo_postal'],
|
||||
'provincia' => $datosEmpresa['provincia'],
|
||||
'telefono' => $datosEmpresa['telefono'],
|
||||
'email' => $datosEmpresa['email'],
|
||||
'cond_iva' => $datosEmpresa['cond_iva'],
|
||||
'cuit' => $datosEmpresa['cuit'],
|
||||
'iva' => $datosEmpresa['iva'],
|
||||
'hora_apertura_maniana' => $datosEmpresa['hora_apertura_maniana'],
|
||||
'hora_cierre_maniana' => $datosEmpresa['hora_cierre_maniana'],
|
||||
'hora_apertura_tarde' => $datosEmpresa['hora_apertura_tarde'],
|
||||
'hora_cierre_tarde' => $datosEmpresa['hora_cierre_tarde'],
|
||||
'mail_automatico' => $datosEmpresa['mail_automatico'],
|
||||
'cargo_cancelacion_servicio' => $datosEmpresa['cargo_cancelacion_servicio'],
|
||||
'email_emisor' => $datosEmpresa['email_emisor'],
|
||||
'contrasenia_emisor' => $datosEmpresa['contrasenia_emisor']
|
||||
]);
|
||||
}
|
||||
|
||||
// OBTENER EL MONTO AL CANCELAR EL SERVICIO
|
||||
|
||||
public function obtenerCargoCancelacion(): float {
|
||||
|
||||
$sql = "SELECT cargo_cancelacion_servicio FROM configuracion WHERE id = 1";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
return isset($row['cargo_cancelacion_servicio']) ? (float) $row['cargo_cancelacion_servicio'] : 0.0;
|
||||
}
|
||||
|
||||
// OBTENER DATOS NECESARIOS PARA EL ENVIO DE EMAIL
|
||||
|
||||
public function obtenerDatosEnvioMail(): array {
|
||||
|
||||
$sql = "SELECT direccion, ciudad, telefono, email, hora_apertura_maniana, hora_cierre_maniana, hora_apertura_tarde, hora_cierre_tarde, email_emisor, contrasenia_emisor, mail_automatico, cargo_cancelacion_servicio FROM configuracion
|
||||
WHERE id = 1";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// OBTENER FECHA DE ULTIMO BACKUP
|
||||
|
||||
public function obtenerFechaUltimoBackup(): ?string {
|
||||
|
||||
$backupDir = __DIR__ . '/../backups/';
|
||||
|
||||
$archivos = glob($backupDir . '*.sql');
|
||||
|
||||
if (!$archivos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ordenar por fecha de modificación (más reciente primero)
|
||||
|
||||
usort($archivos, function ($a, $b) {
|
||||
return filemtime($b) - filemtime($a);
|
||||
});
|
||||
|
||||
// Tomar el archivo más reciente
|
||||
|
||||
$ultimoArchivo = $archivos[0];
|
||||
|
||||
// Obtener fecha desde filemtime
|
||||
|
||||
$timestamp = filemtime($ultimoArchivo);
|
||||
|
||||
// Formatear a Y-m-d
|
||||
|
||||
return date('Y-m-d', $timestamp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user