예제 #1
0
 protected function private_core()
 {
     $this->cliente = new cliente();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->proveedor = new proveedor();
     $this->regularizacion = new regularizacion_iva();
     $serie = new serie();
     $this->series = $serie->all();
     $this->opciones = array('ventas' => TRUE, 'compras' => TRUE, 'fecha' => 'hoy');
     $this->codserie = FALSE;
     if (isset($_REQUEST['codserie'])) {
         $this->codserie = $_REQUEST['codserie'];
     }
     if (isset($_REQUEST['fecha'])) {
         $this->opciones['fecha'] = $_REQUEST['fecha'];
         $this->total = 0;
         if (isset($_REQUEST['ventas'])) {
             $albaran_cli = new albaran_cliente();
             foreach ($albaran_cli->all_ptefactura(0, 'fecha ASC', $this->codserie) as $alb) {
                 $this->generar_factura_cliente(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de cliente facturados.');
         } else {
             $this->opciones['ventas'] = FALSE;
         }
         $this->total = 0;
         if (isset($_REQUEST['compras'])) {
             $albaran_pro = new albaran_proveedor();
             foreach ($albaran_pro->all_ptefactura(0, 'fecha ASC', $this->codserie) as $alb) {
                 $this->generar_factura_proveedor(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de proveedor facturados.');
         } else {
             $this->opciones['compras'] = FALSE;
         }
     }
 }
예제 #2
0
 public function check()
 {
     $eje = new ejercicio();
     $serie = new serie();
     foreach ($eje->all() as $e) {
         $secs = $this->all_from_ejercicio($e->codejercicio);
         foreach ($serie->all() as $serie) {
             $encontrada = FALSE;
             foreach ($secs as $s) {
                 if ($s->codserie == $serie->codserie) {
                     $encontrada = TRUE;
                 }
             }
             if (!$encontrada) {
                 $aux = new secuencia_ejercicio();
                 $aux->codejercicio = $e->codejercicio;
                 $aux->codserie = $serie->codserie;
                 if (!$aux->save()) {
                     $this->new_error_msg("¡Imposible crear la secuencia para el ejercicio " . $aux->codejercicio . " y la serie " . $aux->codserie . "!");
                 }
             }
         }
     }
 }
예제 #3
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')) {
                     /**
                      * 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;
     }
 }
예제 #4
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;
     }
 }