Skip to content

Commit

Permalink
- Eliminados tests obsoletos de balances.
Browse files Browse the repository at this point in the history
- Añadido test unitario del modelo IdentificadorFiscal.
  • Loading branch information
NeoRazorX committed Jun 6, 2022
1 parent d91130f commit be629cd
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 172 deletions.
94 changes: 45 additions & 49 deletions Core/Base/Migrations.php
Expand Up @@ -21,7 +21,6 @@

use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Dinamic\Model\EstadoDocumento;
use FacturaScripts\Dinamic\Model\FormatoDocumento;
use FacturaScripts\Dinamic\Model\LogMessage;

/**
Expand All @@ -31,10 +30,10 @@
*/
final class Migrations
{
private static $database;

public static function run()
{
self::initModels();
self::unlockNullProducts();
self::updateInvoiceStatus();
self::fixInvoiceLines();
Expand All @@ -55,22 +54,30 @@ private static function clearLogs()
}

// cuando hay miles de registros en el canal master, eliminamos los antiguos para evitar problemas de rendimiento
$dataBase = new DataBase();
$date = date("Y-m-d H:i:s", strtotime("-1 month"));
$sql = "DELETE FROM logs WHERE channel = 'master' AND time < '" . $date . "';";
$dataBase->exec($sql);
self::db()->exec($sql);
}

private static function db(): DataBase
{
if (self::$database === null) {
self::$database = new DataBase();
}

return self::$database;
}

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

// si no está la columna debeme, terminamos
$columns = $dataBase->getColumns('partidas');
$columns = self::db()->getColumns('partidas');
if (!isset($columns['debeme'])) {
return;
}
Expand All @@ -80,92 +87,81 @@ private static function fixAccountingEntries()
$sql = strtolower(FS_DB_TYPE) === 'mysql' ?
"ALTER TABLE partidas MODIFY " . $column . " double NULL DEFAULT NULL;" :
"ALTER TABLE partidas ALTER COLUMN " . $column . " DROP NOT NULL;";
$dataBase->exec($sql);
self::db()->exec($sql);
}
}

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

private static function fixClients()
{
$dataBase = new DataBase();
// version 2022.09, fecha 05-06-2022
$table = 'clientes';
if ($dataBase->tableExists($table)) {
$sqlUpdate1 = "UPDATE " . $table . " SET debaja = false WHERE debaja IS NULL;";
$dataBase->exec($sqlUpdate1);
$sqlUpdate2 = "UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;";
$dataBase->exec($sqlUpdate2);
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);
}
}

private static function fixContacts()
{
$dataBase = new DataBase();
// version 2022.09, fecha 05-06-2022
$table = 'contactos';
if ($dataBase->tableExists($table)) {
$sqlUpdate1 = "UPDATE " . $table . " SET aceptaprivacidad = false WHERE aceptaprivacidad IS NULL;";
$dataBase->exec($sqlUpdate1);
$sqlUpdate2 = "UPDATE " . $table . " SET admitemarketing = false WHERE admitemarketing IS NULL;";
$dataBase->exec($sqlUpdate2);
$sqlUpdate3 = "UPDATE " . $table . " SET habilitado = true WHERE habilitado IS NULL;";
$dataBase->exec($sqlUpdate3);
$sqlUpdate4 = "UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;";
$dataBase->exec($sqlUpdate4);
$sqlUpdate5 = "UPDATE " . $table . " SET verificado = false WHERE verificado IS NULL;";
$dataBase->exec($sqlUpdate5);
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 habilitado = true WHERE habilitado IS NULL;"
. " UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;"
. " UPDATE " . $table . " SET verificado = false WHERE verificado IS NULL;";
self::db()->exec($sqlUpdate);
}
}

private static function fixInvoiceLines()
{
$dataBase = new DataBase();
// version 2022.09, fecha 05-06-2022
$tables = ['lineasfacturascli', 'lineasfacturasprov'];
foreach ($tables as $table) {
if ($dataBase->tableExists($table)) {
if (self::db()->tableExists($table)) {
$sql = "UPDATE " . $table . " SET irpf = '0' WHERE irpf IS NULL;";
$dataBase->exec($sql);
self::db()->exec($sql);
}
}
}

private static function fixSuppliers()
{
$dataBase = new DataBase();
// version 2022.09, fecha 05-06-2022
$table = 'proveedores';
if ($dataBase->tableExists($table)) {
$sqlUpdate1 = "UPDATE " . $table . " SET acreedor = false WHERE acreedor IS NULL;";
$dataBase->exec($sqlUpdate1);
$sqlUpdate2 = "UPDATE " . $table . " SET debaja = false WHERE debaja IS NULL;";
$dataBase->exec($sqlUpdate2);
$sqlUpdate3 = "UPDATE " . $table . " SET personafisica = true WHERE personafisica IS NULL;";
$dataBase->exec($sqlUpdate3);
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);
}
}

private static function initModels()
{
new FormatoDocumento();
}

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

private static function updateInvoiceStatus()
{
// version 2021.81, fecha 01-02-2022
$status = new EstadoDocumento();
if ($status->loadFromCode('10') && $status->nombre === 'Nueva') {
// unlock
Expand Down
2 changes: 1 addition & 1 deletion Core/Base/PluginManager.php
Expand Up @@ -32,7 +32,7 @@ final class PluginManager
/**
* FacturaScripts core version.
*/
const CORE_VERSION = 2022.09;
const CORE_VERSION = 2022.1;

/**
* Path to list plugins on file.
Expand Down
10 changes: 7 additions & 3 deletions Core/Model/IdentificadorFiscal.php
Expand Up @@ -62,9 +62,13 @@ public static function tableName(): string

public function test(): bool
{
$this->tipoidfiscal = trim($this->tipoidfiscal);
if (1 !== preg_match('/^[A-Z0-9_\+\.\-]{1,25}$/i', $this->tipoidfiscal)) {
$this->toolBox()->i18nLog()->error(
// escapamos el html
$this->codeid = self::toolBox()::utils()::noHtml($this->codeid);
$this->tipoidfiscal = self::toolBox()::utils()::noHtml($this->tipoidfiscal);

// comprobamos que el campo tenga un valor válido
if (empty($this->tipoidfiscal) || 1 !== preg_match('/^[A-Z0-9_\+\.\-]{1,25}$/i', $this->tipoidfiscal)) {
self::toolBox()::i18nLog()->error(
'invalid-alphanumeric-code',
['%value%' => $this->tipoidfiscal, '%column%' => 'tipoidfiscal', '%min%' => '1', '%max%' => '25']
);
Expand Down
8 changes: 4 additions & 4 deletions Core/Translation/en_EN.json
Expand Up @@ -212,7 +212,7 @@
"closing-accounting-completed": "Accounting closing process completed successfully",
"closing-closing-concept": "Closing entry for exercise %exercise%",
"closing-opening-concept": "Opening entry for exercise %exercise%",
"closing-operation": "Cierre",
"closing-operation": "Closing",
"closing-regularization-concept": "Regularization entry for exercise %exercise%",
"codbarras": "Barcode",
"code": "Code",
Expand Down Expand Up @@ -859,8 +859,8 @@
"open-exercise": "Open exercise",
"opened": "Opened",
"opening-acounting-completed": "Opening acounting completed",
"opening-operation": "Apertura",
"operation": "Operación",
"opening-operation": "Opening",
"operation": "Operation",
"option": "Option",
"optional": "optional",
"options": "Options",
Expand Down Expand Up @@ -1020,7 +1020,7 @@
"register-symbol": "#",
"registered-installation": "Registered installation #%number%",
"registered-installation-p": "This installation has already been registered. If you have payment plugins, press the manage button to link them and be able to update.",
"regularization-operation": "Regularización",
"regularization-operation": "Regularization",
"reject": "Reject",
"rejected": "Rejected",
"related": "Related",
Expand Down
8 changes: 4 additions & 4 deletions Core/Translation/eu_ES.json
Expand Up @@ -212,7 +212,7 @@
"closing-accounting-completed": "Ekitaldia ondo itxita",
"closing-closing-concept": "%exercise% ekitaldia itxiera idazpena",
"closing-opening-concept": "%exercise% ekitaldiaren irekitze idazpena",
"closing-operation": "Cierre",
"closing-operation": "Itxiera",
"closing-regularization-concept": "%exercise% ekitaldiaren erregularizazio idazpena",
"codbarras": "Barra-kodea",
"code": "Kodea",
Expand Down Expand Up @@ -859,8 +859,8 @@
"open-exercise": "Ekitaldia ireki",
"opened": "Irekita",
"opening-acounting-completed": "Ekitaldi irekitze zuzena",
"opening-operation": "Apertura",
"operation": "Operación",
"opening-operation": "Irekitzea",
"operation": "Operazioa",
"option": "Aukera",
"optional": "aukerakoa",
"options": "Aukerak",
Expand Down Expand Up @@ -1020,7 +1020,7 @@
"register-symbol": "#",
"registered-installation": "Instalazio erregistratua #%number%",
"registered-installation-p": "Instalazio hau dagoeneko erregistratuta dago. Ordainketa pluginak badituzu, sakatu kudeatu botoia hauek lotzeko eta eguneratu ahal izateko.",
"regularization-operation": "Regularización",
"regularization-operation": "Erregularizazioa",
"reject": "Baztertu",
"rejected": "Ukatua",
"related": "Erlazionatuta",
Expand Down
37 changes: 0 additions & 37 deletions Test/Core/Model/BalanceCuentaATest.php

This file was deleted.

37 changes: 0 additions & 37 deletions Test/Core/Model/BalanceCuentaTest.php

This file was deleted.

37 changes: 0 additions & 37 deletions Test/Core/Model/BalanceTest.php

This file was deleted.

0 comments on commit be629cd

Please sign in to comment.