private function test_tablas() { $recargar = FALSE; if ($this->informe['offset'] == 0) { /// comprobamos la tabla familias if ($this->db->table_exists('familias')) { $data = $this->db->select("SELECT * FROM familias WHERE madre IS NOT NULL AND madre NOT IN (SELECT codfamilia FROM familias);"); if ($data) { foreach ($data as $d) { $familia = new familia($d); $familia->madre = NULL; $familia->save(); } } } /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { $this->db->exec("DELETE FROM articulosprov WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 1) { /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { $this->db->exec("UPDATE articulosprov SET refproveedor = referencia WHERE refproveedor IS NULL;"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 2) { /// comprobamos la tabla de stock if ($this->db->table_exists('stocks')) { /** * Esta consulta produce un error si no hay datos erroneos, pero da igual */ $this->db->exec("DELETE FROM stocks s WHERE NOT EXISTS " . "(SELECT referencia FROM articulos a WHERE a.referencia = s.referencia);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 3) { /// comprobamos la tabla de regulaciones de stock if ($this->db->table_exists('lineasregstocks')) { $this->db->exec("DELETE FROM lineasregstocks WHERE idstock NOT IN (SELECT idstock FROM stocks);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 4) { /// eliminamos los elementos de contabilidad que apuntan a ejercicios que no existen $tablas = array('co_gruposepigrafes', 'co_epigrafes', 'co_cuentas', 'co_subcuentas'); foreach ($tablas as $tabla) { $this->db->exec("DELETE FROM " . $tabla . " WHERE codejercicio NOT IN (SELECT codejercicio FROM ejercicios);"); } /// comprobamos la tabla de subcuentas de proveedores if ($this->db->table_exists('co_subcuentasprov')) { $this->db->exec("DELETE FROM co_subcuentasprov WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } /// comprobamos la tabla de direcciones de proveedores if ($this->db->table_exists('dirproveedores')) { $this->db->exec("DELETE FROM dirproveedores WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } /// comprobamos la tabla de subcuentas de clientes if ($this->db->table_exists('co_subcuentascli')) { $this->db->exec("DELETE FROM co_subcuentascli WHERE codcliente NOT IN (SELECT codcliente FROM clientes);"); } /// comprobamos la tabla de direcciones de clientes if ($this->db->table_exists('dirclientes')) { $this->db->exec("DELETE FROM dirclientes WHERE codcliente NOT IN (SELECT codcliente FROM clientes);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 5) { /// comprobamos la tabla de epigrafes if ($this->db->table_exists('co_epigrafes')) { $this->db->exec("UPDATE co_epigrafes SET idgrupo = NULL WHERE idgrupo NOT IN (SELECT idgrupo FROM co_gruposepigrafes);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 6) { $almacen = new almacen(); if (!$almacen->all()) { $this->db->exec($almacen->install()); } $divisa = new divisa(); if (!$divisa->all()) { $this->db->exec($divisa->install()); } $formap = new forma_pago(); if (!$formap->all()) { $this->db->exec($formap->install()); } $pais = new pais(); if (!$pais->all()) { $this->db->exec($pais->install()); } $serie = new serie(); if (!$serie->all()) { $this->db->exec($serie->install()); } $recargar = TRUE; $this->informe['offset'] += 1; } else { /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { /// buscamos duplicados $data = $this->db->select("SELECT codproveedor,refproveedor,COUNT(*) as count FROM articulosprov GROUP BY codproveedor,refproveedor HAVING COUNT(*) > 1;"); if ($data) { foreach ($data as $d) { $sql = "SELECT * FROM articulosprov WHERE codproveedor = " . $this->empresa->var2str($d['codproveedor']) . " AND refproveedor = " . $this->empresa->var2str($d['refproveedor']) . ";"; $data2 = $this->db->select($sql); if ($data2) { $this->db->exec("DELETE FROM articulosprov WHERE id = " . $this->empresa->var2str($data2[1]['id']) . ";"); } } $recargar = TRUE; $this->informe['offset'] += 1; } } } } } } } } } if (!$recargar) { if ($this->informe['all']) { $this->informe['model'] = 'asiento'; } else { $this->informe['model'] = 'fin'; } $this->informe['offset'] = 0; } }
private function test_tablas() { $recargar = FALSE; if ($this->informe['offset'] == 0) { /// comprobamos la tabla familias if ($this->db->table_exists('familias')) { $data = $this->db->select("SELECT * FROM familias WHERE madre IS NOT NULL AND madre NOT IN (SELECT codfamilia FROM familias);"); if ($data) { foreach ($data as $d) { $familia = new familia($d); $familia->madre = NULL; $familia->save(); } } } /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { $this->db->exec("DELETE FROM articulosprov WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 1) { /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { $this->db->exec("UPDATE articulosprov SET refproveedor = referencia WHERE refproveedor IS NULL;"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 2) { /// comprobamos la tabla de stock if ($this->db->table_exists('stocks')) { $this->db->exec("DELETE FROM stocks s WHERE NOT EXISTS (SELECT referencia FROM articulos a WHERE a.referencia = s.referencia);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 3) { /// comprobamos la tabla de regulaciones de stock if ($this->db->table_exists('lineasregstocks')) { $this->db->exec("DELETE FROM lineasregstocks WHERE idstock NOT IN (SELECT idstock FROM stocks);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 4) { /// comprobamos la tabla de subcuentas de proveedores if ($this->db->table_exists('co_subcuentasprov')) { $this->db->exec("DELETE FROM co_subcuentasprov WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } /// comprobamos la tabla de direcciones de proveedores if ($this->db->table_exists('dirproveedores')) { $this->db->exec("DELETE FROM dirproveedores WHERE codproveedor NOT IN (SELECT codproveedor FROM proveedores);"); } /// comprobamos la tabla de subcuentas de clientes if ($this->db->table_exists('co_subcuentascli')) { $this->db->exec("DELETE FROM co_subcuentascli WHERE codcliente NOT IN (SELECT codcliente FROM clientes);"); } /// comprobamos la tabla de direcciones de clientes if ($this->db->table_exists('dirclientes')) { $this->db->exec("DELETE FROM dirclientes WHERE codcliente NOT IN (SELECT codcliente FROM clientes);"); } $recargar = TRUE; $this->informe['offset'] += 1; } else { if ($this->informe['offset'] == 5) { $almacen = new almacen(); if (!$almacen->all()) { $this->db->exec($almacen->install()); } $divisa = new divisa(); if (!$divisa->all()) { $this->db->exec($divisa->install()); } $formap = new forma_pago(); if (!$formap->all()) { $this->db->exec($formap->install()); } $pais = new pais(); if (!$pais->all()) { $this->db->exec($pais->install()); } $serie = new serie(); if (!$serie->all()) { $this->db->exec($serie->install()); } $recargar = TRUE; $this->informe['offset'] += 1; } else { /// comprobamos la tabla de articulos de proveedor if ($this->db->table_exists('articulosprov')) { /// buscamos duplicados $data = $this->db->select("SELECT codproveedor,refproveedor,COUNT(*) as count FROM articulosprov GROUP BY codproveedor,refproveedor HAVING COUNT(*) > 1;"); if ($data) { foreach ($data as $d) { $data2 = $this->db->select("SELECT * FROM articulosprov WHERE codproveedor = '" . $d['codproveedor'] . "' AND refproveedor = '" . $d['refproveedor'] . "';"); if ($data2) { $this->db->exec("DELETE FROM articulosprov WHERE id = " . $this->empresa->var2str($data2[1]['id']) . ";"); } } $recargar = TRUE; $this->informe['offset'] += 1; } } } } } } } } if (!$recargar) { if ($this->informe['all']) { $this->informe['model'] = 'asiento'; } else { $this->informe['model'] = 'fin'; } $this->informe['offset'] = 0; } }