Skip to content

Commit

Permalink
Añadido código para volver a añadir las formas de pago eliminadas.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoRazorX committed Apr 15, 2024
1 parent d1c4da0 commit e7f98db
Showing 1 changed file with 19 additions and 191 deletions.
210 changes: 19 additions & 191 deletions Core/Base/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Model\EmailNotification;
use FacturaScripts\Dinamic\Model\EstadoDocumento;
use FacturaScripts\Dinamic\Model\FormaPago;
use FacturaScripts\Dinamic\Model\LogMessage;
use FacturaScripts\Dinamic\Model\Serie;
use ParseCsv\Csv;

/**
* Description of Migrations
Expand All @@ -39,36 +37,9 @@ final class Migrations

public static function run(): void
{
self::unlockNullProducts();
self::updateInvoiceStatus();
self::updateExceptionVatCompany();
self::fixInvoiceLines();
self::fixAccountingEntries();
self::fixContacts();
self::fixAgents();
self::fixClients();
self::fixSuppliers();
self::clearLogs();
self::addEmailNotifications();
self::fixSeries();
}

private static function addEmailNotifications(): void
{
$csv = new Csv();
$csv->auto(FS_FOLDER . '/Dinamic/Data/Lang/ES/emails_notifications.csv');
foreach ($csv->data as $row) {
$notification = new EmailNotification();
$where = [new DataBaseWhere('name', $row['name'])];
if (false === $notification->loadFromCode('', $where)) {
// no existe, la creamos
$notification->enabled = true;
$notification->name = $row['name'];
$notification->subject = $row['subject'];
$notification->body = $row['body'];
$notification->save();
}
}
self::fixFormasPago();
}

private static function clearLogs(): void
Expand All @@ -94,71 +65,25 @@ private static function db(): DataBase
return self::$database;
}

// version 2022.09, fecha 05-06-2022
private static function fixAccountingEntries(): void
{
// si no existe la tabla 'partidas', terminamos
if (false === self::db()->tableExists('partidas')) {
return;
}

// si no está la columna debeme, terminamos
$columns = self::db()->getColumns('partidas');
if (!isset($columns['debeme'])) {
return;
}

// marcamos como null las columnas 'debeme' y 'haberme'
foreach (['debeme', 'haberme'] as $column) {
$sql = strtolower(FS_DB_TYPE) === 'mysql' ?
"ALTER TABLE partidas MODIFY " . $column . " double NULL DEFAULT NULL;" :
"ALTER TABLE partidas ALTER COLUMN " . $column . " DROP NOT NULL;";
self::db()->exec($sql);
}
}

// version 2022.09, fecha 05-06-2022
private static function fixAgents(): void
{
$table = 'agentes';
if (self::db()->tableExists($table)) {
$sqlUpdate = "UPDATE " . $table . " SET debaja = false WHERE debaja IS NULL;";
self::db()->exec($sqlUpdate);
}
}

// version 2022.09, fecha 05-06-2022
private static function fixClients(): void
{
$table = 'clientes';
if (self::db()->tableExists($table)) {
$sqlUpdate = "UPDATE " . $table . " SET debaja = false WHERE debaja IS NULL;"
. " UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;";
self::db()->exec($sqlUpdate);
}
}

// version 2022.09, fecha 05-06-2022
private static function fixContacts(): void
{
$table = 'contactos';
if (self::db()->tableExists($table)) {
$sqlUpdate = "UPDATE " . $table . " SET aceptaprivacidad = false WHERE aceptaprivacidad IS NULL;"
. " UPDATE " . $table . " SET admitemarketing = false WHERE admitemarketing IS NULL;"
. " UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;"
. " UPDATE " . $table . " SET verificado = false WHERE verificado IS NULL;";
self::db()->exec($sqlUpdate);
}
}

// version 2022.09, fecha 05-06-2022
private static function fixInvoiceLines(): void
// versión 2024.5, fecha 15-04-2024
private static function fixFormasPago(): void
{
$tables = ['lineasfacturascli', 'lineasfacturasprov'];
// forzamos la comprobación de la tabla formas_pago
new FormaPago();

// recorremos las tablas de documentos de compra o venta
$tables = [
'albaranescli', 'albaranesprov', 'facturascli', 'facturasprov', 'pedidoscli', 'pedidosprov',
'presupuestoscli', 'presupuestosprov'
];
foreach ($tables as $table) {
if (self::db()->tableExists($table)) {
$sql = "UPDATE " . $table . " SET irpf = '0' WHERE irpf IS NULL;";
self::db()->exec($sql);
// buscamos aquellos códigos de pago que no estén en la tabla formaspago
$sql = "SELECT DISTINCT codpago FROM " . $table . " WHERE codpago NOT IN (SELECT codpago FROM formaspago);";
foreach (self::db()->select($sql) as $row) {
$formaPago = new FormaPago();
$formaPago->codpago = $row['codpago'];
$formaPago->descripcion = Tools::lang()->trans('deleted');
$formaPago->save();
}
}
}
Expand All @@ -178,101 +103,4 @@ private static function fixSeries(): void
$sqlUpdate = "UPDATE series SET tipo = 'R' WHERE codserie = " . self::db()->var2str($serieRectifying) . ";";
self::db()->exec($sqlUpdate);
}

// version 2022.09, fecha 05-06-2022
private static function fixSuppliers(): void
{
$table = 'proveedores';
if (self::db()->tableExists($table)) {
$sqlUpdate = "UPDATE " . $table . " SET acreedor = false WHERE acreedor IS NULL;"
. " UPDATE " . $table . " SET debaja = false WHERE debaja IS NULL;"
. " UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;";
self::db()->exec($sqlUpdate);
}
}

// version 2022.06, fecha 05-05-2022
private static function unlockNullProducts(): void
{
if (self::db()->tableExists('productos')) {
$sql = 'UPDATE productos SET bloqueado = false WHERE bloqueado IS NULL;';
self::db()->exec($sql);
}
}

private static function updateExceptionVatCompany(): void
{
$existIVA = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . FS_DB_NAME . "' AND TABLE_NAME = 'empresas' AND COLUMN_NAME = 'excepcioniva';";
$existVAT = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . FS_DB_NAME . "' AND TABLE_NAME = 'empresas' AND COLUMN_NAME = 'exceptioniva';";

// comprobamos si existe la columna excepcioniva en la tabla
// si no existe, pero si existe la columna exceptioniva
// renombramos la columna exceptioniva por excepcioniva de la tabla
if (empty(self::db()->select($existIVA)) && false === empty(self::db()->select($existVAT))) {
$sql = "ALTER TABLE empresas CHANGE exceptioniva excepcioniva VARCHAR(20) NULL DEFAULT NULL;";
self::db()->exec($sql);
return;
}

// si existe la columna excepcioniva y exceptioniva,
// copiamos el valor de la columna exceptioniva a la columna excepcioniva
// y eliminamos la columna exceptioniva
if (false === empty(self::db()->select($existIVA)) && false === empty(self::db()->select($existVAT))) {
$sql = "UPDATE empresas SET excepcioniva = exceptioniva;";
self::db()->exec($sql);
$sql = "ALTER TABLE empresas DROP COLUMN exceptioniva;";
self::db()->exec($sql);
}
}

// version 2021.81, fecha 01-02-2022
private static function updateInvoiceStatus(): void
{
$status = new EstadoDocumento();
if ($status->loadFromCode('10') && $status->nombre === 'Nueva') {
// unlock
$status->bloquear = false;
$status->save();
// update
$status->bloquear = true;
$status->editable = true;
$status->nombre = 'Boceto';
$status->predeterminado = true;
$status->save();
}

if ($status->loadFromCode('11') && $status->nombre === 'Completada') {
// unlock
$status->bloquear = false;
$status->save();
// update
$status->bloquear = true;
$status->editable = false;
$status->nombre = 'Emitida';
$status->save();
}

if ($status->loadFromCode('21') && $status->nombre === 'Nueva') {
// unlock
$status->bloquear = false;
$status->save();
// update
$status->bloquear = true;
$status->editable = true;
$status->nombre = 'Boceto';
$status->predeterminado = true;
$status->save();
}

if ($status->loadFromCode('22') && $status->nombre === 'Completada') {
// unlock
$status->bloquear = false;
$status->save();
// update
$status->bloquear = true;
$status->editable = false;
$status->nombre = 'Recibida';
$status->save();
}
}
}

0 comments on commit e7f98db

Please sign in to comment.