Ejemplo n.º 1
0
 protected function process()
 {
     /// declaramos los objetos sólo para asegurarnos de que existen las tablas
     $albaran_cli = new albaran_cliente();
     $albaran_pro = new albaran_proveedor();
     $this->mostrar = 'stats';
     if (isset($_REQUEST['mostrar'])) {
         $this->mostrar = $_REQUEST['mostrar'];
     }
     $this->tipo = 'ventas';
     if (isset($_REQUEST['tipo'])) {
         $this->tipo = $_REQUEST['tipo'];
     }
     if ($this->mostrar == 'listado') {
         $this->desde = Date('1-m-Y');
         $this->hasta = Date('d-m-Y', mktime(0, 0, 0, date("m") + 1, date("1") - 1, date("Y")));
         if (isset($_POST['desde'])) {
             $this->desde = $_POST['desde'];
             $this->hasta = $_POST['hasta'];
         }
         if ($this->tipo == 'ventas') {
             $this->resultados = $albaran_cli->all_desde($this->desde, $this->hasta);
         } else {
             $this->resultados = $albaran_pro->all_desde($this->desde, $this->hasta);
         }
     }
 }
Ejemplo n.º 2
0
 public function __construct(&$db)
 {
     $alb_cli = new albaran_cliente();
     echo "Ejecutando tareas para los " . FS_ALBARANES . " de cliente...\n";
     $alb_cli->cron_job();
     $alb_pro = new albaran_proveedor();
     echo "Ejecutando tareas para los " . FS_ALBARANES . " de proveedor...\n";
     $alb_pro->cron_job();
     $articulo = new articulo();
     echo "Ejecutando tareas para los artículos...";
     $articulo->cron_job();
     $asiento = new asiento();
     echo "\nEjecutando tareas para los asientos...\n";
     $asiento->cron_job();
     if (FS_LIBROS_CONTABLES) {
         $libro = new libro_mayor();
         echo "Generamos el libro mayor para cada subcuenta y el libro diario para cada ejercicio...";
         $libro->cron_job();
         $inventarios_balances = new inventarios_balances();
         echo "\nGeneramos el libro de inventarios y balances para cada ejercicio...";
         $inventarios_balances->cron_job();
     } else {
         $libro = new libro_mayor();
         echo "Comprobamos algunas subcuentas...";
         $libro->cron_job();
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->cliente = new cliente();
     $this->ejercicio = new ejercicio();
     $this->proveedor = new proveedor();
     $this->regularizacion = new regularizacion_iva();
     $this->opciones = array('ventas' => TRUE, 'compras' => TRUE, 'fecha' => 'hoy');
     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, 'ASC') 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, 'ASC') as $alb) {
                 $this->generar_factura_proveedor(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de proveedor facturados.');
         } else {
             $this->opciones['compras'] = FALSE;
         }
     }
 }
 protected function process()
 {
     $albaran = new albaran_cliente();
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     /// Usamos una cookie para recordar si el usuario quiere ver los pendientes
     $this->pendientes = isset($_COOKIE['ventas_alb_ptes']);
     if (isset($_GET['ptefactura'])) {
         $this->pendientes = $_GET['ptefactura'] == 'TRUE';
         if ($this->pendientes) {
             setcookie('ventas_alb_ptes', 'TRUE', time() + FS_COOKIES_EXPIRE);
         } else {
             setcookie('ventas_alb_ptes', FALSE, time() - FS_COOKIES_EXPIRE);
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/ventas_albaranes_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $albaran->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codcliente'])) {
                 $this->template = 'extension/ventas_albaranes_cliente';
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($_GET['codcliente']);
                 $this->resultados = $albaran->all_from_cliente($_GET['codcliente'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/ventas_albaranes_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_albaran_cliente();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_POST['delete'])) {
                         $this->delete_albaran();
                     }
                     if ($this->query) {
                         $this->resultados = $albaran->search($this->query, $this->offset);
                     } else {
                         if ($this->pendientes) {
                             $this->resultados = $albaran->all_ptefactura($this->offset);
                         } else {
                             $this->resultados = $albaran->all($this->offset);
                         }
                     }
                 }
             }
         }
     }
 }
 protected function process()
 {
     $this->ppage = $this->page->get('ventas_albaranes');
     $this->agente = FALSE;
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $albaran = new albaran_cliente();
     $this->albaran = FALSE;
     $this->cliente = new cliente();
     $this->cliente_s = FALSE;
     $this->ejercicio = new ejercicio();
     $this->familia = new familia();
     $this->impuesto = new impuesto();
     $this->nuevo_albaran_url = FALSE;
     $this->serie = new serie();
     /**
      * Comprobamos si el usuario tiene acceso a nueva_venta,
      * necesario para poder añadir líneas.
      */
     if ($this->user->have_access_to('nueva_venta', FALSE)) {
         $nuevoalbp = $this->page->get('nueva_venta');
         if ($nuevoalbp) {
             $this->nuevo_albaran_url = $nuevoalbp->url();
         }
     }
     if (isset($_POST['idalbaran'])) {
         $this->albaran = $albaran->get($_POST['idalbaran']);
         $this->modificar();
     } else {
         if (isset($_GET['id'])) {
             $this->albaran = $albaran->get($_GET['id']);
         }
     }
     if ($this->albaran) {
         $this->page->title = $this->albaran->codigo;
         /// cargamos el agente
         if (!is_null($this->albaran->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->albaran->codagente);
         }
         /// cargamos el cliente
         $this->cliente_s = $this->cliente->get($this->albaran->codcliente);
         /// comprobamos el albarán
         if ($this->albaran->full_test()) {
             if (isset($_GET['facturar']) and isset($_GET['petid']) and $this->albaran->ptefactura) {
                 if ($this->duplicated_petition($_GET['petid'])) {
                     $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.');
                 } else {
                     $this->generar_factura();
                 }
             }
         }
     } else {
         $this->new_error_msg("¡" . FS_ALBARAN . " de cliente no encontrado!");
     }
 }
Ejemplo n.º 6
0
 protected function private_core()
 {
     $this->albaran = FALSE;
     $this->cliente = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     /// obtenemos los datos de configuración de impresión
     $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0');
     $fsvar = new fs_var();
     $this->impresion = $fsvar->array_get($this->impresion, FALSE);
     $this->logo = FALSE;
     if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) {
         $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.png';
     } else {
         if (file_exists('tmp/' . FS_TMP_NAME . 'logo.jpg')) {
             $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.jpg';
         }
     }
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_cliente();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->albaran->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('albaran');
         } else {
             $this->generar_pdf_albaran();
         }
     } else {
         if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) {
             $fac = new factura_cliente();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($this->factura->codcliente);
             }
             if (isset($_POST['email'])) {
                 $this->enviar_email('factura', $_REQUEST['tipo']);
             } else {
                 $this->generar_pdf_factura($_REQUEST['tipo']);
             }
         }
     }
     $this->share_extensions();
 }
Ejemplo n.º 7
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;
         }
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->albaran = FALSE;
     $this->cliente = FALSE;
     $this->factura = FALSE;
     $this->impuesto = new impuesto();
     if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
         $alb = new albaran_cliente();
         $this->albaran = $alb->get($_REQUEST['id']);
         if ($this->albaran) {
             $cliente = new cliente();
             $this->cliente = $cliente->get($this->albaran->codcliente);
         }
         if (isset($_POST['email'])) {
             $this->enviar_email('albaran');
         } else {
             $this->generar_pdf_albaran();
         }
     } else {
         if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) {
             $fac = new factura_cliente();
             $this->factura = $fac->get($_REQUEST['id']);
             if ($this->factura) {
                 $cliente = new cliente();
                 $this->cliente = $cliente->get($this->factura->codcliente);
             }
             if (isset($_POST['email'])) {
                 $this->enviar_email('factura', $_REQUEST['tipo']);
             } else {
                 $this->generar_pdf_factura($_REQUEST['tipo']);
             }
         }
     }
     $this->share_extensions();
 }
Ejemplo n.º 9
0
 private function test_models()
 {
     $mpp = 100;
     $last_errores = array();
     switch ($this->informe['model']) {
         default:
             /// tablas
             $this->test_tablas();
             break;
         case 'asiento':
             $asiento = new asiento();
             $asientos = $asiento->all($this->informe['offset'], $mpp);
             if ($asientos) {
                 if ($this->informe['offset'] == 0) {
                     foreach ($this->check_partidas_erroneas() as $err) {
                         $last_errores[] = $err;
                     }
                 }
                 foreach ($asientos as $asi) {
                     if ($asi->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$asi->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $asi->codejercicio, 'id' => $asi->numero, 'url' => $asi->url(), 'fecha' => $asi->fecha, 'fix' => $asi->fix());
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura cliente':
             $factura = new factura_cliente();
             $facturas = $factura->all($this->informe['offset'], $mpp);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura proveedor':
             $factura = new factura_proveedor();
             $facturas = $factura->all($this->informe['offset'], $mpp);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran cliente':
             $albaran = new albaran_cliente();
             $albaranes = $albaran->all($this->informe['offset'], $mpp);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran proveedor':
             $albaran = new albaran_proveedor();
             $albaranes = $albaran->all($this->informe['offset'], $mpp);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         $this->informe['model'] = 'fin';
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 $this->informe['model'] = 'fin';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'fin':
             break;
     }
     return $last_errores;
 }
Ejemplo n.º 10
0
 protected function private_core()
 {
     $this->ppage = $this->page->get('ventas_albaranes');
     $this->agente = FALSE;
     $albaran = new albaran_cliente();
     $this->albaran = FALSE;
     $this->cliente = new cliente();
     $this->cliente_s = FALSE;
     $this->divisa = new divisa();
     $this->ejercicio = new ejercicio();
     $this->fabricante = new fabricante();
     $this->familia = new familia();
     $this->forma_pago = new forma_pago();
     $this->impuesto = new impuesto();
     $this->nuevo_albaran_url = FALSE;
     $this->pais = new pais();
     $this->serie = new serie();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     /**
      * Comprobamos si el usuario tiene acceso a nueva_venta,
      * necesario para poder añadir líneas.
      */
     if ($this->user->have_access_to('nueva_venta', FALSE)) {
         $nuevoalbp = $this->page->get('nueva_venta');
         if ($nuevoalbp) {
             $this->nuevo_albaran_url = $nuevoalbp->url();
         }
     }
     if (isset($_POST['idalbaran'])) {
         $this->albaran = $albaran->get($_POST['idalbaran']);
         $this->modificar();
     } else {
         if (isset($_GET['id'])) {
             $this->albaran = $albaran->get($_GET['id']);
         }
     }
     if ($this->albaran) {
         $this->page->title = $this->albaran->codigo;
         /// cargamos el agente
         if (!is_null($this->albaran->codagente)) {
             $agente = new agente();
             $this->agente = $agente->get($this->albaran->codagente);
         }
         /// cargamos el cliente
         $this->cliente_s = $this->cliente->get($this->albaran->codcliente);
         /// comprobamos el albarán
         $this->albaran->full_test();
         if (isset($_GET['facturar']) and isset($_GET['petid'])) {
             if ($this->duplicated_petition($_GET['petid'])) {
                 $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.');
             } else {
                 if (!$this->albaran->ptefactura or !is_null($this->albaran->idfactura)) {
                     $this->new_error_msg('Parece que este ' . FS_ALBARAN . ' ya está facturado.');
                 } else {
                     $this->generar_factura();
                 }
             }
         } else {
             if (isset($_GET['forze_fecha'])) {
                 $this->forzar_fecha();
             }
         }
     } else {
         $this->new_error_msg("¡" . FS_ALBARAN . " de cliente no encontrado!");
     }
 }
Ejemplo n.º 11
0
 private function generar_albaran()
 {
     $albaran = new albaran_cliente();
     $albaran->apartado = $this->pedido->apartado;
     $albaran->cifnif = $this->pedido->cifnif;
     $albaran->ciudad = $this->pedido->ciudad;
     $albaran->codagente = $this->pedido->codagente;
     $albaran->codalmacen = $this->pedido->codalmacen;
     $albaran->codcliente = $this->pedido->codcliente;
     $albaran->coddir = $this->pedido->coddir;
     $albaran->coddivisa = $this->pedido->coddivisa;
     $albaran->tasaconv = $this->pedido->tasaconv;
     $albaran->codpago = $this->pedido->codpago;
     $albaran->codpais = $this->pedido->codpais;
     $albaran->codpostal = $this->pedido->codpostal;
     $albaran->codserie = $this->pedido->codserie;
     $albaran->direccion = $this->pedido->direccion;
     $albaran->neto = $this->pedido->neto;
     $albaran->nombrecliente = $this->pedido->nombrecliente;
     $albaran->observaciones = $this->pedido->observaciones;
     $albaran->provincia = $this->pedido->provincia;
     $albaran->total = $this->pedido->total;
     $albaran->totaliva = $this->pedido->totaliva;
     $albaran->numero2 = $this->pedido->numero2;
     $albaran->irpf = $this->pedido->irpf;
     $albaran->porcomision = $this->pedido->porcomision;
     $albaran->totalirpf = $this->pedido->totalirpf;
     $albaran->totalrecargo = $this->pedido->totalrecargo;
     if (isset($_POST['facturar'])) {
         $albaran->fecha = $_POST['facturar'];
     }
     /**
      * Obtenemos el ejercicio para la fecha de hoy (puede que
      * no sea el mismo ejercicio que el del pedido, por ejemplo
      * si hemos cambiado de año)
      */
     $eje0 = $this->ejercicio->get_by_fecha($albaran->fecha, FALSE);
     if ($eje0) {
         $albaran->codejercicio = $eje0->codejercicio;
     }
     if (!$eje0) {
         $this->new_error_msg("Ejercicio no encontrado.");
     } else {
         if (!$eje0->abierto()) {
             $this->new_error_msg("El ejercicio está cerrado.");
         } else {
             if ($albaran->save()) {
                 $continuar = TRUE;
                 $art0 = new articulo();
                 foreach ($this->pedido->get_lineas() as $l) {
                     $n = new linea_albaran_cliente();
                     $n->idlineapedido = $l->idlinea;
                     $n->idpedido = $l->idpedido;
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     if ($n->save()) {
                         /// descontamos del stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             if ($articulo) {
                                 $articulo->sum_stock($albaran->codalmacen, 0 - $l->cantidad);
                             }
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($continuar) {
                     $this->pedido->idalbaran = $albaran->idalbaran;
                     if ($this->pedido->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
                         if (isset($_POST['facturar'])) {
                             header('Location: ' . $albaran->url() . '&facturar=' . $_POST['facturar'] . '&petid=' . $this->random_string());
                         }
                     } else {
                         $this->new_error_msg("¡Imposible vincular el " . FS_PEDIDO . " con el nuevo " . FS_ALBARAN . "!");
                         if ($albaran->delete()) {
                             $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                         } else {
                             $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                         }
                     }
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
 public function full_test($duplicados = TRUE)
 {
     $status = TRUE;
     /// comprobamos las líneas
     $neto = 0;
     $iva = 0;
     $irpf = 0;
     $recargo = 0;
     foreach ($this->get_lineas() as $l) {
         if (!$l->test()) {
             $status = FALSE;
         }
         $neto += $l->pvptotal;
         $iva += $l->pvptotal * $l->iva / 100;
         $irpf += $l->pvptotal * $l->irpf / 100;
         $recargo += $l->pvptotal * $l->recargo / 100;
     }
     $neto = round($neto, FS_NF0);
     $iva = round($iva, FS_NF0);
     $irpf = round($irpf, FS_NF0);
     $recargo = round($recargo, FS_NF0);
     $total = $neto + $iva - $irpf + $recargo;
     if (!$this->floatcmp($this->neto, $neto, FS_NF0, TRUE)) {
         $this->new_error_msg("Valor neto de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $neto);
         $status = FALSE;
     } else {
         if (!$this->floatcmp($this->totaliva, $iva, FS_NF0, TRUE)) {
             $this->new_error_msg("Valor totaliva de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $iva);
             $status = FALSE;
         } else {
             if (!$this->floatcmp($this->totalirpf, $irpf, FS_NF0, TRUE)) {
                 $this->new_error_msg("Valor totalirpf de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $irpf);
                 $status = FALSE;
             } else {
                 if (!$this->floatcmp($this->totalrecargo, $recargo, FS_NF0, TRUE)) {
                     $this->new_error_msg("Valor totalrecargo de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $recargo);
                     $status = FALSE;
                 } else {
                     if (!$this->floatcmp($this->total, $total, FS_NF0, TRUE)) {
                         $this->new_error_msg("Valor total de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $total);
                         $status = FALSE;
                     } else {
                         if (!$this->floatcmp($this->totaleuros, $this->total * $this->tasaconv, FS_NF0, TRUE)) {
                             $this->new_error_msg("Valor totaleuros de " . FS_PEDIDO . " incorrecto.\n            Valor correcto: " . round($this->total * $this->tasaconv, FS_NF0));
                             $status = FALSE;
                         }
                     }
                 }
             }
         }
     }
     if ($this->idalbaran) {
         $alb0 = new albaran_cliente();
         $albaran = $alb0->get($this->idalbaran);
         if (!$albaran) {
             $this->idalbaran = NULL;
             $this->status = 0;
             $this->editable = TRUE;
             $this->save();
         }
     }
     return $status;
 }
Ejemplo n.º 13
0
 private function generar_albaran()
 {
     $albaran = new albaran_cliente();
     $albaran->apartado = $this->servicio->apartado;
     $albaran->cifnif = $this->servicio->cifnif;
     $albaran->ciudad = $this->servicio->ciudad;
     $albaran->codagente = $this->servicio->codagente;
     if ($this->servicio->codalmacen != '') {
         $albaran->codalmacen = $this->servicio->codalmacen;
     } else {
         $albaran->codalmacen = $this->empresa->codalmacen;
     }
     $albaran->codcliente = $this->servicio->codcliente;
     $albaran->coddir = $this->servicio->coddir;
     $albaran->coddivisa = $this->servicio->coddivisa;
     $albaran->tasaconv = $this->servicio->tasaconv;
     $albaran->codpago = $this->servicio->codpago;
     $albaran->codpais = $this->servicio->codpais;
     $albaran->codpostal = $this->servicio->codpostal;
     $albaran->codserie = $this->servicio->codserie;
     $albaran->direccion = $this->servicio->direccion;
     $albaran->neto = $this->servicio->neto;
     $albaran->nombrecliente = $this->servicio->nombrecliente;
     $albaran->observaciones = "Servicio: " . $this->servicio->codigo . " | Fecha: " . $this->servicio->fecha . "\nDescripcion: " . $this->servicio->descripcion . "\nSolución: " . $this->servicio->solucion . "\nObservaciones: " . $this->servicio->observaciones;
     $albaran->provincia = $this->servicio->provincia;
     $albaran->total = $this->servicio->total;
     $albaran->totaliva = $this->servicio->totaliva;
     $albaran->numero2 = $this->servicio->numero2;
     $albaran->irpf = $this->servicio->irpf;
     $albaran->porcomision = $this->servicio->porcomision;
     $albaran->totalirpf = $this->servicio->totalirpf;
     $albaran->totalrecargo = $this->servicio->totalrecargo;
     /**
      * Obtenemos el ejercicio para la fecha de hoy (puede que
      * no sea el mismo ejercicio que el del servicio, por ejemplo
      * si hemos cambiado de año)
      */
     $eje0 = $this->ejercicio->get_by_fecha($albaran->fecha);
     $albaran->codejercicio = $eje0->codejercicio;
     if (!$eje0) {
         $this->new_error_msg("Ejercicio no encontrado.");
     } else {
         if (!$eje0->abierto()) {
             $this->new_error_msg("El ejercicio está cerrado.");
         } else {
             if ($albaran->save()) {
                 $continuar = TRUE;
                 $art0 = new articulo();
                 foreach ($this->servicio->get_lineas() as $l) {
                     $n = new linea_albaran_cliente();
                     $n->idlineaservicio = $l->idlinea;
                     $n->idservicio = $l->idservicio;
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     if ($n->save()) {
                         /// descontamos del stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             if ($articulo) {
                                 $articulo->sum_stock($albaran->codalmacen, 0 - $l->cantidad);
                             }
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($continuar) {
                     $this->servicio->idalbaran = $albaran->idalbaran;
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
 protected function private_core()
 {
     $this->share_extension();
     if (isset($_REQUEST["cat"])) {
         switch ($_REQUEST["cat"]) {
             case "fam":
                 if (isset($_REQUEST["cod"])) {
                     $this->codFamilia = $this->db->escape_string($_REQUEST["cod"]);
                 }
                 $catf = new autoventas_familia();
                 if (isset($_REQUEST["action"])) {
                     switch ($_REQUEST["action"]) {
                         case 1:
                             // Actualitzem dades
                             $catf->nombre = $this->db->escape_string($_REQUEST["fam_nombre"]);
                             $catf->descripcion = $this->db->escape_string($_REQUEST["fam_descripcion"]);
                             if (isset($_REQUEST["fam_visible"])) {
                                 $catf->visible = 1;
                             } else {
                                 $catf->visible = 0;
                             }
                             $catf->codigo = $this->codFamilia;
                             $catf->save();
                             break;
                         case 2:
                             // Pugem foto
                             $imagen = $this->guarda_foto_familia($this->codFamilia);
                             if ($imagen) {
                                 $this->familia = $catf->load_data($this->codFamilia);
                                 $catf->codigo = $this->familia["codigo"];
                                 $catf->nombre = $this->familia["nombre"];
                                 $catf->descripcion = $this->familia["descripcion"];
                                 $catf->visible = $this->familia["visible"];
                                 $catf->imagen = $imagen;
                                 $catf->save();
                                 $this->new_message("Imagen subida correctamente : {$imagen}");
                             }
                             break;
                         case 3:
                             // Borrem foto
                             if ($this->borra_foto($this->codFamilia)) {
                                 $this->new_message("Imagen borrada correctamente");
                                 $this->familia = $catf->load_data($this->codFamilia);
                                 $catf->codigo = $this->familia["codigo"];
                                 $catf->nombre = $this->familia["nombre"];
                                 $catf->descripcion = $this->familia["descripcion"];
                                 $catf->visible = $this->familia["visible"];
                                 $catf->imagen = "";
                                 $catf->save();
                             } else {
                                 $this->new_error_msg("Hubo un problema a la hora de borrar la imagen");
                             }
                             break;
                         default:
                             $this->new_error_msg("Autoventas: Código de accion desconocido");
                     }
                 } else {
                     $catf->codigo = $this->codFamilia;
                     if (!$catf->exists()) {
                         // No existeix, afegim les dades que tenim per defecte.
                         $fam = new familia();
                         $f1 = $fam->get($this->codFamilia);
                         $catf->codigo = $f1->codfamilia;
                         $catf->nombre = $f1->codfamilia;
                         $catf->descripcion = $f1->descripcion;
                         $catf->visible = 1;
                         $catf->imagen = "";
                         $catf->save();
                     }
                 }
                 $this->familia = $catf->load_data($this->codFamilia);
                 $this->template = "autoventas_familias";
                 break;
             case "firma":
                 if (isset($_REQUEST["tipo"])) {
                     $this->tipo = $_REQUEST["tipo"];
                     $this->id = (int) $_REQUEST["id"];
                     switch ($this->tipo) {
                         case "albaran":
                             if (isset($_REQUEST["action"])) {
                                 $accion = $_REQUEST["action"];
                             } else {
                                 $accion = "";
                             }
                             require_model("albaran_cliente.php");
                             $a = new albaran_cliente();
                             $b = $a->get($this->id);
                             $numero2 = $b->numero2;
                             $path = "images/autoventas/firmas";
                             switch ($accion) {
                                 case "sincroniza":
                                     $op = new autoventas_opcionesdb();
                                     $opciones = new autoventas_opcionesdb($op->load());
                                     $url = $opciones->url . "/images/autoventas/firmas/{$numero2}.jpg";
                                     if (@get_headers($url)[0] == 'HTTP/1.1 404 Not Found') {
                                         $this->new_error_msg('El archivo de firma no existe.');
                                     } else {
                                         $archivo = file_get_contents($url);
                                         if ($archivo) {
                                             file_put_contents($path . "/" . $numero2 . ".jpg", $archivo);
                                         }
                                     }
                                     break;
                                 case "borra":
                                     if (file_exists($path . "/{$numero2}.jpg")) {
                                         unlink($path . "/{$numero2}.jpg");
                                     }
                                     break;
                                 default:
                             }
                             if (!file_exists($path)) {
                                 if (!mkdir($path, 0777, TRUE)) {
                                     $this->new_error_msg('Error al crear la carpeta images/autoventas/familias.');
                                 }
                             }
                             if (!file_exists($path . "/{$numero2}.jpg")) {
                                 $this->firmaUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAMAAABOo35HAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAH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+kmVZmn0fVDp+6HGga2NdpkqvEnnTIy+9wrHqoOl0Xej0/cuOuF1ZGuzXWbFJUobeH2fNYdeck/+4jBsre/xIhL75e1eghV84MXou9E4FktlbKTvg1bfu66z1OmCR33DTGlJI1ZfHl/6YmRJH578gy7SWLVn1b5f3b2sEs+OGvtKKeFabmXsINMMfeD2zKHcgmV4I5Qsjb47kWTlFH7gHln2wsM88/3MzDmi7lFa+qFbdf6e+VSCfbXI6XvKs6JDtpNiR/NRx51gLliGl4ZhdeaQ+UgjkLBA9NhHFl9wrLS+B47VdY/wrPKp90xXOak+fKTBxevQSybQ1FJLcnxpPuo2CSzGtYzQWbzCsbxEy3L5GJ8Mx7j9wnbnW997kWNlREENSzEZOvEkwXoWuyTlcmkDo+/0j6d4x+K/gZWFoTwK+QTB1HhW5pXDnkkb0mIX/HXQmumDOwOrub4f3DN44Cbqlvl+NgS+ZtLoPaHudnsQLJW+dzX6zrkWr+/R/x/6nhgasWOdgqXR97FK3zlYucUOn3MseueXGROfk+Wq1noW+e/yzhNM9wqV7KWWD6NEK1lt5s7EK9f49VfGs3w5QYo64j8bWm5bAZDzX/G22jX9w7ZtSfvMd0ith5v27dA9b92nycttTdjx+eO9Nj+Yr8WJZS/A+g6QdfHFlQWU2jBEASzAAizA+qMLZkN4FmABFmABFgpmQ3gWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAEWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAEWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAHWY8q/AwC5r4fHLh7jqQAAAABJRU5ErkJggg==";
                                 $this->firmaSolicitar = 1;
                             } else {
                                 $this->firmaUrl = "{$path}/{$numero2}.jpg";
                                 $this->firmaSolicitar = 0;
                             }
                             break;
                         case "pedido":
                             if (isset($_REQUEST["action"])) {
                                 $accion = $_REQUEST["action"];
                             } else {
                                 $accion = "";
                             }
                             require_model("pedido_cliente.php");
                             $a = new pedido_cliente();
                             $b = $a->get($this->id);
                             $numero2 = $b->numero2;
                             $path = "images/autoventas/firmas";
                             switch ($accion) {
                                 case "sincroniza":
                                     $op = new autoventas_opcionesdb();
                                     $opciones = new autoventas_opcionesdb($op->load());
                                     $url = $opciones->url . "/images/autoventas/firmas/{$numero2}.jpg";
                                     if (@get_headers($url)[0] == 'HTTP/1.1 404 Not Found') {
                                         $this->new_error_msg('El archivo de firma no existe.');
                                     } else {
                                         $archivo = file_get_contents($url);
                                         if ($archivo) {
                                             file_put_contents($path . "/" . $numero2 . ".jpg", $archivo);
                                         }
                                     }
                                     break;
                                 case "borra":
                                     if (file_exists($path . "/{$numero2}.jpg")) {
                                         unlink($path . "/{$numero2}.jpg");
                                     }
                                     break;
                                 default:
                             }
                             if (!file_exists($path)) {
                                 if (!mkdir($path, 0777, TRUE)) {
                                     $this->new_error_msg('Error al crear la carpeta images/autoventas/familias.');
                                 }
                             }
                             if (!file_exists($path . "/{$numero2}.jpg")) {
                                 $this->firmaUrl = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAMAAABOo35HAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA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kN4FmABFmABFgpmQ3gWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAEWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAEWYAEWYAEWCmABFmABFmABFgpgARZgARZgARYKYAHWY8q/AwC5r4fHLh7jqQAAAABJRU5ErkJggg==";
                                 $this->firmaSolicitar = 1;
                             } else {
                                 $this->firmaUrl = "{$path}/{$numero2}.jpg";
                                 $this->firmaSolicitar = 0;
                             }
                             break;
                         default:
                             $this->new_error_msg("Autoventas: Tipo de documento desconocido");
                     }
                 }
                 $this->template = "autoventas_firma";
                 break;
             case "imprimir":
                 $this->albaran = FALSE;
                 $this->cliente = FALSE;
                 $this->pedido = FALSE;
                 $this->impuesto = new impuesto();
                 /// obtenemos los datos de configuración de impresión
                 $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0', 'print_formapago' => '1');
                 $fsvar = new fs_var();
                 $this->impresion = $fsvar->array_get($this->impresion, FALSE);
                 $this->logo = FALSE;
                 if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) {
                     $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.png';
                 } else {
                     if (file_exists('tmp/' . FS_TMP_NAME . 'logo.jpg')) {
                         $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.jpg';
                     }
                 }
                 if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) {
                     $alb = new albaran_cliente();
                     $this->albaran = $alb->get($_REQUEST['id']);
                     if ($this->albaran) {
                         $cliente = new cliente();
                         $this->cliente = $cliente->get($this->albaran->codcliente);
                     }
                     if (isset($_POST['email'])) {
                         $this->enviar_email('albaran');
                     } else {
                         $this->generar_pdf_albaran();
                     }
                 } else {
                     if (isset($_REQUEST['pedido']) and isset($_REQUEST['id'])) {
                         require_model("pedido_cliente.php");
                         $fac = new pedido_cliente();
                         $this->pedido = $fac->get($_REQUEST['id']);
                         if ($this->pedido) {
                             $cliente = new cliente();
                             $this->cliente = $cliente->get($this->pedido->codcliente);
                         }
                         if (isset($_POST['email'])) {
                             $this->enviar_email('pedido');
                         } else {
                             $this->generar_pdf_pedido();
                         }
                     }
                 }
                 break;
             default:
                 $this->new_error_msg('Autoventas: Error categoría desconocida');
         }
     } else {
         $this->new_error_msg('Autoventas: Error sin categoría');
     }
 }
Ejemplo n.º 15
0
 private function nuevo_albaran_cliente($p)
 {
     // print_r($p);
     $continuar = TRUE;
     $respuesta = "";
     $cliente = $this->cliente->get($p['cliente']);
     if (!$cliente) {
         $respuesta .= 'Cliente no encontrado.';
         $continuar = FALSE;
     }
     $almacen = $this->almacen->get($p['almacen']);
     if ($almacen) {
     } else {
         $respuesta .= 'Almacén no encontrado.';
         $continuar = FALSE;
     }
     $eje0 = new ejercicio();
     $ejercicio = $eje0->get_by_fecha($p['fecha'], FALSE);
     if (!$ejercicio) {
         $respuesta .= 'Ejercicio no encontrado.';
         $continuar = FALSE;
     }
     $serie = $this->serie->get($p['serie']);
     if (!$serie) {
         $respuesta .= 'Serie no encontrada.';
         $continuar = FALSE;
     }
     $forma_pago = $this->forma_pago->get($p['forma_pago']);
     if ($forma_pago) {
     } else {
         $respuesta .= 'Forma de pago no encontrada.';
         $continuar = FALSE;
     }
     $divisa = $this->divisa->get($p['divisa']);
     if (!$divisa) {
         $respuesta .= 'Divisa no encontrada.';
         $continuar = FALSE;
     }
     $albaran = new albaran_cliente();
     if ($continuar) {
         $albaran->fecha = $p['fecha'];
         $albaran->hora = $p['hora'];
         $albaran->codalmacen = $almacen->codalmacen;
         $albaran->codejercicio = $ejercicio->codejercicio;
         $albaran->codserie = $serie->codserie;
         $albaran->codpago = $forma_pago->codpago;
         $albaran->coddivisa = $divisa->coddivisa;
         $albaran->tasaconv = $divisa->tasaconv;
         $albaran->codagente = $this->agente->codagente;
         $albaran->numero2 = $p['numero2'];
         $albaran->observaciones = $p['observaciones'];
         $albaran->porcomision = $this->agente->porcomision;
         $albaran->codcliente = $cliente->codcliente;
         $albaran->cifnif = $cliente->cifnif;
         $albaran->nombrecliente = $cliente->nombre;
         $direccion = array();
         foreach ($cliente->get_direcciones() as $dir) {
             if ($dir->domfacturacion) {
                 $direccion = $dir;
                 break;
             }
         }
         $albaran->ciudad = $direccion->ciudad;
         $albaran->codpais = $direccion->codpais;
         $albaran->codpostal = $direccion->codpostal;
         $albaran->direccion = $direccion->direccion;
         $albaran->provincia = $direccion->provincia;
         if ($albaran->save()) {
             $art0 = new articulo();
             $n = floatval($p['numlineas']);
             for ($i = 0; $i <= $n; $i++) {
                 if (isset($p['referencia_' . $i])) {
                     $linea = new linea_albaran_cliente();
                     $linea->idalbaran = $albaran->idalbaran;
                     $linea->descripcion = $p['desc_' . $i];
                     if (!$serie->siniva and $cliente->regimeniva != 'Exento') {
                         $imp0 = $this->impuesto->get_by_iva($p['iva_' . $i]);
                         if ($imp0) {
                             $linea->codimpuesto = $imp0->codimpuesto;
                             $linea->iva = floatval($p['iva_' . $i]);
                             $linea->recargo = floatval($p['recargo_' . $i]);
                         } else {
                             $linea->iva = floatval($p['iva_' . $i]);
                             $linea->recargo = floatval($p['recargo_' . $i]);
                         }
                     }
                     $linea->irpf = floatval($p['irpf_' . $i]);
                     $linea->pvpunitario = floatval($p['pvp_' . $i]);
                     $linea->cantidad = floatval($p['cantidad_' . $i]);
                     $linea->dtopor = floatval($p['dto_' . $i]);
                     $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                     $linea->pvptotal = floatval($p['neto_' . $i]);
                     $articulo = $art0->get($p['referencia_' . $i]);
                     if ($articulo) {
                         $linea->referencia = $articulo->referencia;
                     }
                     if ($linea->save()) {
                         if ($articulo and isset($p['stock'])) {
                             /// descontamos del stock
                             $articulo->sum_stock($albaran->codalmacen, 0 - $linea->cantidad);
                         }
                         $albaran->neto += $linea->pvptotal;
                         $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                         $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                         $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                         if ($linea->irpf > $albaran->irpf) {
                             $albaran->irpf = $linea->irpf;
                         }
                     } else {
                         $respuesta .= "¡Imposible guardar la linea con referencia: " . $linea->referencia;
                         $continuar = FALSE;
                     }
                 }
             }
             if ($continuar) {
                 /// redondeamos
                 $albaran->neto = round($albaran->neto, FS_NF0);
                 $albaran->totaliva = round($albaran->totaliva, FS_NF0);
                 $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
                 $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
                 $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
                 if ($albaran->save()) {
                     $respuesta .= "Albarán correcto";
                 } else {
                     $respuesta .= "¡Imposible actualizar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!";
                 }
             } else {
                 if ($albaran->delete()) {
                     $respuesta .= FS_ALBARAN . " eliminado correctamente.";
                 } else {
                     $respuesta .= "¡Imposible eliminar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!";
                 }
             }
         } else {
             $respuesta .= "¡Imposible guardar el " . FS_ALBARAN . "!";
         }
     }
     return $respuesta;
 }
 private function get_movimientos($ref, $desde = '', $hasta = '', $codagente = '')
 {
     $mlist = array();
     $regularizacion = new regularizacion_stock();
     foreach ($regularizacion->all_from_articulo($ref) as $reg) {
         $anyadir = TRUE;
         if ($desde != '') {
             if (strtotime($desde) > strtotime($reg->fecha)) {
                 $anyadir = FALSE;
             }
         }
         if ($hasta != '') {
             if (strtotime($hasta) < strtotime($reg->fecha)) {
                 $anyadir = FALSE;
             }
         }
         if ($anyadir) {
             $mlist[] = array('referencia' => $ref, 'codalmacen' => $reg->codalmacendest, 'origen' => 'Regularización', 'url' => 'index.php?page=ventas_articulo&ref=' . $ref, 'clipro' => '-', 'movimiento' => '-', 'precio' => 0, 'dto' => 0, 'final' => $reg->cantidadfin, 'fecha' => $reg->fecha, 'hora' => $reg->hora);
         }
     }
     /// forzamos la comprobación de las tablas de albaranes
     $albc = new albaran_cliente();
     $lin1 = new linea_albaran_cliente();
     $albp = new albaran_proveedor();
     $lin2 = new linea_albaran_proveedor();
     $sql_extra = '';
     if ($desde != '') {
         $sql_extra .= " AND fecha >= " . $this->empresa->var2str($desde);
     }
     if ($hasta != '') {
         $sql_extra .= " AND fecha <= " . $this->empresa->var2str($hasta);
     }
     if ($codagente != '') {
         $sql_extra .= " AND codagente = " . $this->empresa->var2str($codagente);
     }
     /// buscamos el artículo en albaranes de compra
     $sql = "SELECT a.codigo,l.cantidad,l.pvpunitario,l.dtopor,a.fecha,a.hora" . ",a.codalmacen,a.idalbaran,a.codproveedor,a.nombre" . " FROM albaranesprov a, lineasalbaranesprov l" . " WHERE a.idalbaran = l.idalbaran AND l.referencia = " . $albc->var2str($ref) . $sql_extra;
     $data = $this->db->select_limit($sql, 1000, 0);
     if ($data) {
         foreach ($data as $d) {
             $mlist[] = array('referencia' => $ref, 'codalmacen' => $d['codalmacen'], 'origen' => 'Albaran compra ' . $d['codigo'], 'url' => 'index.php?page=compras_albaran&id=' . $d['idalbaran'], 'clipro' => $d['codproveedor'] . ' - ' . $d['nombre'], 'movimiento' => floatval($d['cantidad']), 'precio' => floatval($d['pvpunitario']), 'dto' => floatval($d['dtopor']), 'final' => 0, 'fecha' => date('d-m-Y', strtotime($d['fecha'])), 'hora' => $d['hora']);
         }
     }
     /// buscamos el artículo en facturas de compra
     $sql = "SELECT f.codigo,l.cantidad,l.pvpunitario,l.dtopor,f.fecha,f.hora" . ",f.codalmacen,f.idfactura,f.codproveedor,f.nombre" . " FROM facturasprov f, lineasfacturasprov l" . " WHERE f.idfactura = l.idfactura AND l.idalbaran IS NULL" . " AND l.referencia = " . $albc->var2str($ref) . $sql_extra;
     $data = $this->db->select_limit($sql, 1000, 0);
     if ($data) {
         foreach ($data as $d) {
             $mlist[] = array('referencia' => $ref, 'codalmacen' => $d['codalmacen'], 'origen' => 'Factura compra ' . $d['codigo'], 'url' => 'index.php?page=compras_factura&id=' . $d['idfactura'], 'clipro' => $d['codproveedor'] . ' - ' . $d['nombre'], 'movimiento' => floatval($d['cantidad']), 'precio' => floatval($d['pvpunitario']), 'dto' => floatval($d['dtopor']), 'final' => 0, 'fecha' => date('d-m-Y', strtotime($d['fecha'])), 'hora' => $d['hora']);
         }
     }
     /// buscamos el artículo en albaranes de venta
     $sql = "SELECT a.codigo,l.cantidad,l.pvpunitario,l.dtopor,a.fecha,a.hora" . ",a.codalmacen,a.idalbaran,a.codcliente,a.nombrecliente" . " FROM albaranescli a, lineasalbaranescli l" . " WHERE a.idalbaran = l.idalbaran AND l.referencia = " . $albc->var2str($ref) . $sql_extra;
     $data = $this->db->select_limit($sql, 1000, 0);
     if ($data) {
         foreach ($data as $d) {
             $mlist[] = array('referencia' => $ref, 'codalmacen' => $d['codalmacen'], 'origen' => 'Albaran venta ' . $d['codigo'], 'url' => 'index.php?page=ventas_albaran&id=' . $d['idalbaran'], 'clipro' => $d['codcliente'] . ' - ' . $d['nombrecliente'], 'movimiento' => 0 - floatval($d['cantidad']), 'precio' => floatval($d['pvpunitario']), 'dto' => floatval($d['dtopor']), 'final' => 0, 'fecha' => date('d-m-Y', strtotime($d['fecha'])), 'hora' => $d['hora']);
         }
     }
     /// buscamos el artículo en facturas de venta
     $sql = "SELECT f.codigo,l.cantidad,l.pvpunitario,l.dtopor,f.fecha,f.hora" . ",f.codalmacen,f.idfactura,f.codcliente,f.nombrecliente" . " FROM facturascli f, lineasfacturascli l" . " WHERE f.idfactura = l.idfactura AND l.idalbaran IS NULL" . " AND l.referencia = " . $albc->var2str($ref) . $sql_extra;
     $data = $this->db->select_limit($sql, 1000, 0);
     if ($data) {
         foreach ($data as $d) {
             $mlist[] = array('referencia' => $ref, 'codalmacen' => $d['codalmacen'], 'origen' => 'Factura venta ' . $d['codigo'], 'url' => 'index.php?page=ventas_factura&id=' . $d['idfactura'], 'clipro' => $d['codcliente'] . ' - ' . $d['nombrecliente'], 'movimiento' => 0 - floatval($d['cantidad']), 'precio' => floatval($d['pvpunitario']), 'dto' => floatval($d['dtopor']), 'final' => 0, 'fecha' => date('d-m-Y', strtotime($d['fecha'])), 'hora' => $d['hora']);
         }
     }
     /// ordenamos por fecha y hora
     usort($mlist, function ($a, $b) {
         if (strtotime($a['fecha'] . ' ' . $a['hora']) == strtotime($b['fecha'] . ' ' . $b['hora'])) {
             return 0;
         } else {
             if (strtotime($a['fecha'] . ' ' . $a['hora']) < strtotime($b['fecha'] . ' ' . $b['hora'])) {
                 return -1;
             } else {
                 return 1;
             }
         }
     });
     /// recalculamos
     $inicial = 0;
     foreach (array_reverse($mlist) as $i => $value) {
         if ($value['movimiento'] == '-') {
             $inicial = $value['final'];
         } else {
             $inicial -= $value['movimiento'];
         }
     }
     $total = max(array($inicial, 0));
     foreach ($mlist as $i => $value) {
         if ($value['movimiento'] == '-') {
             $total = $value['final'];
         } else {
             $total += $value['movimiento'];
         }
         $mlist[$i]['final'] = $total;
     }
     return $mlist;
 }
Ejemplo n.º 17
0
 private function generar_albaran()
 {
     $albaran = new albaran_cliente();
     $albaran->apartado = $this->servicio->apartado;
     $albaran->cifnif = $this->servicio->cifnif;
     $albaran->ciudad = $this->servicio->ciudad;
     $albaran->codagente = $this->servicio->codagente;
     if ($this->servicio->codalmacen) {
         $albaran->codalmacen = $this->servicio->codalmacen;
     } else {
         $albaran->codalmacen = $this->empresa->codalmacen;
     }
     $albaran->codcliente = $this->servicio->codcliente;
     $albaran->coddir = $this->servicio->coddir;
     $albaran->coddivisa = $this->servicio->coddivisa;
     $albaran->tasaconv = $this->servicio->tasaconv;
     $albaran->codpago = $this->servicio->codpago;
     $albaran->codpais = $this->servicio->codpais;
     $albaran->codpostal = $this->servicio->codpostal;
     $albaran->codserie = $this->servicio->codserie;
     $albaran->direccion = $this->servicio->direccion;
     $albaran->neto = $this->servicio->neto;
     $albaran->nombrecliente = $this->servicio->nombrecliente;
     $albaran->observaciones = $this->servicio->observaciones;
     $albaran->provincia = $this->servicio->provincia;
     $albaran->total = $this->servicio->total;
     $albaran->totaliva = $this->servicio->totaliva;
     $albaran->numero2 = $this->servicio->numero2;
     $albaran->irpf = $this->servicio->irpf;
     $albaran->porcomision = $this->servicio->porcomision;
     $albaran->totalirpf = $this->servicio->totalirpf;
     $albaran->totalrecargo = $this->servicio->totalrecargo;
     /**
      * Obtenemos el ejercicio para la fecha de hoy (puede que
      * no sea el mismo ejercicio que el del servicio, por ejemplo
      * si hemos cambiado de año)
      */
     $eje0 = $this->ejercicio->get_by_fecha($albaran->fecha);
     $albaran->codejercicio = $eje0->codejercicio;
     if (!$eje0) {
         $this->new_error_msg("Ejercicio no encontrado.");
     } else {
         if (!$eje0->abierto()) {
             $this->new_error_msg("El ejercicio está cerrado.");
         } else {
             if ($albaran->save()) {
                 $this->new_message("El " . FS_ALBARAN . " " . $albaran->codigo . " ha sido creado correctamente.");
                 $continuar = TRUE;
                 $art0 = new articulo();
                 $i = 0;
                 foreach ($this->servicio->get_lineas() as $l) {
                     $n = new linea_albaran_cliente();
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     if ($i == 0) {
                         if ($this->setup['servicios_linea'] && $this->setup['servicios_linea1']) {
                             $n->descripcion .= "\n";
                             if ($this->setup['servicios_material_linea']) {
                                 $n->descripcion .= $this->setup['st_material'] . ": " . $this->servicio->material . "\n";
                             }
                             if ($this->setup['servicios_material_estado_linea']) {
                                 $n->descripcion .= $this->setup['st_material_estado'] . ": " . $this->servicio->material_estado . "\n";
                             }
                             if ($this->setup['servicios_accesorios_linea']) {
                                 $n->descripcion .= $this->setup['st_accesorios'] . ": " . $this->servicio->accesorios . "\n";
                             }
                             if ($this->setup['servicios_descripcion_linea']) {
                                 $n->descripcion .= $this->setup['st_descripcion'] . ": " . $this->servicio->descripcion . "\n";
                             }
                             if ($this->setup['servicios_solucion_linea']) {
                                 $n->descripcion .= $this->setup['st_solucion'] . ": " . $this->servicio->solucion . "\n";
                             }
                             if ($this->setup['servicios_fechainicio_linea']) {
                                 $n->descripcion .= $this->setup['st_fechainicio'] . ": " . $this->servicio->fechainicio . "   ";
                             }
                             if ($this->setup['servicios_fechafin_linea']) {
                                 $n->descripcion .= $this->setup['st_fechafin'] . ": " . $this->servicio->fechafin . "   ";
                             }
                             if ($this->setup['servicios_garantia_linea']) {
                                 $n->descripcion .= $this->setup['st_garantia'] . ": " . $this->servicio->garantia . "\n";
                             }
                         }
                     }
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     $i++;
                     if ($n->save()) {
                         /// descontamos del stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             if ($articulo) {
                                 $articulo->sum_stock($albaran->codalmacen, 0 - $l->cantidad);
                             }
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($this->setup['servicios_linea'] && !$this->setup['servicios_linea1']) {
                     /// generamos la linea con detalles del servicio
                     if ($this->setup['servicios_linea']) {
                         $ns = new linea_albaran_cliente();
                         $ns->idalbaran = $albaran->idalbaran;
                         $ns->cantidad = '0';
                         /// usamos el impuestos por defecto
                         $imp0 = new impuesto();
                         foreach ($imp0->all() as $imp) {
                             if ($imp->is_default()) {
                                 $ns->codimpuesto = $imp->codimpuesto;
                                 $ns->iva = $imp->iva;
                             }
                         }
                         $ns->descripcion = FS_SERVICIO . ": " . $this->servicio->codigo . " Fecha: " . $this->servicio->fecha . "\n";
                         if ($this->setup['servicios_material_linea']) {
                             $ns->descripcion .= $this->setup['st_material'] . ": " . $this->servicio->material . "\n";
                         }
                         if ($this->setup['servicios_material_estado_linea']) {
                             $ns->descripcion .= $this->setup['st_material_estado'] . ": " . $this->servicio->material_estado . "\n";
                         }
                         if ($this->setup['servicios_accesorios_linea']) {
                             $ns->descripcion .= $this->setup['st_accesorios'] . ": " . $this->servicio->accesorios . "\n";
                         }
                         if ($this->setup['servicios_descripcion_linea']) {
                             $ns->descripcion .= $this->setup['st_descripcion'] . ": " . $this->servicio->descripcion . "\n";
                         }
                         if ($this->setup['servicios_solucion_linea']) {
                             $ns->descripcion .= $this->setup['st_solucion'] . ": " . $this->servicio->solucion . "\n";
                         }
                         if ($this->setup['servicios_fechainicio_linea']) {
                             $ns->descripcion .= $this->setup['st_fechainicio'] . ": " . $this->servicio->fechainicio . "   ";
                         }
                         if ($this->setup['servicios_fechafin_linea']) {
                             $ns->descripcion .= $this->setup['st_fechafin'] . ": " . $this->servicio->fechafin . "   ";
                         }
                         if ($this->setup['servicios_garantia_linea']) {
                             $ns->descripcion .= $this->setup['st_garantia'] . ": " . $this->servicio->garantia . "\n";
                         }
                         $ns->dtopor = '0';
                         $ns->irpf = '0';
                         $ns->pvpsindto = '0';
                         $ns->pvptotal = '0';
                         $ns->pvpunitario = '0';
                         $ns->recargo = '0';
                         $ns->referencia = '';
                         $ns->save();
                     }
                 }
                 if ($continuar) {
                     $this->servicio->idalbaran = $albaran->idalbaran;
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
 private function borrar_ticket()
 {
     $albaran = new albaran_cliente();
     $alb = $albaran->get_by_codigo($_GET['delete']);
     if ($alb) {
         if ($alb->ptefactura) {
             $articulo = new articulo();
             foreach ($alb->get_lineas() as $linea) {
                 $art0 = $articulo->get($linea->referencia);
                 if ($art0) {
                     $art0->sum_stock($alb->codalmacen, $linea->cantidad);
                     $art0->save();
                 }
             }
             if ($alb->delete()) {
                 $this->new_message("Ticket " . $_GET['delete'] . " borrado correctamente.");
                 /// actualizamos la caja
                 $this->caja->dinero_fin -= $alb->total;
                 $this->caja->tickets -= 1;
                 if (!$this->caja->save()) {
                     $this->new_error_msg("¡Imposible actualizar la caja!");
                 }
             } else {
                 $this->new_error_msg("¡Imposible borrar el ticket " . $_GET['delete'] . "!");
             }
         } else {
             $this->new_error_msg('No se ha podido borrar este ' . FS_ALBARAN . ' porque ya está facturado.');
         }
     } else {
         $this->new_error_msg("Ticket no encontrado.");
     }
 }
Ejemplo n.º 19
0
  * y cron_error por si hubiese algún fallo.
  */
 $cron_vars['cron_lock'] = 'TRUE';
 $cron_vars['cron_exists'] = 'TRUE';
 /// guardamos las variables
 $fsvar->array_save($cron_vars);
 /// establecemos los elementos por defecto
 $fs_default_items = new fs_default_items();
 $empresa = new empresa();
 $fs_default_items->set_codalmacen($empresa->codalmacen);
 $fs_default_items->set_coddivisa($empresa->coddivisa);
 $fs_default_items->set_codejercicio($empresa->codejercicio);
 $fs_default_items->set_codpago($empresa->codpago);
 $fs_default_items->set_codpais($empresa->codpais);
 $fs_default_items->set_codserie($empresa->codserie);
 $alb_cli = new albaran_cliente();
 echo "Ejecutando tareas para los " . FS_ALBARANES . " de cliente...\n";
 $alb_cli->cron_job();
 $alb_pro = new albaran_proveedor();
 echo "Ejecutando tareas para los " . FS_ALBARANES . " de proveedor...\n";
 $alb_pro->cron_job();
 $articulo = new articulo();
 echo "Ejecutando tareas para los artículos...";
 $articulo->cron_job();
 $asiento = new asiento();
 echo "\nEjecutando tareas para los asientos...\n";
 $asiento->cron_job();
 $libro = new libro_mayor();
 echo "Generamos el libro mayor para cada subcuenta y el libro diario para cada ejercicio...";
 $libro->cron_job();
 $inventarios_balances = new inventarios_balances();
Ejemplo n.º 20
0
 private function test_models()
 {
     $last_errores = array();
     switch ($this->informe['model']) {
         default:
             /// tablas
             $this->test_tablas();
             break;
         case 'asiento':
             $asiento = new asiento();
             $asientos = $asiento->all($this->informe['offset']);
             if ($asientos) {
                 if ($this->informe['offset'] == 0) {
                     foreach ($this->check_partidas_erroneas() as $err) {
                         $last_errores[] = $err;
                     }
                 }
                 foreach ($asientos as $asi) {
                     if ($asi->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$asi->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $asi->codejercicio, 'id' => $asi->numero, 'url' => $asi->url(), 'fecha' => $asi->fecha, 'fix' => $asi->fix());
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura cliente':
             $factura = new factura_cliente();
             $facturas = $factura->all($this->informe['offset']);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura proveedor':
             $factura = new factura_proveedor();
             $facturas = $factura->all($this->informe['offset']);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran cliente':
             $albaran = new albaran_cliente();
             $albaranes = $albaran->all($this->informe['offset']);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran proveedor':
             $albaran = new albaran_proveedor();
             $albaranes = $albaran->all($this->informe['offset']);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         $this->informe['model'] = 'fin';
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 $this->informe['model'] = 'dirclientes';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'dirclientes':
             $dircli0 = new direccion_cliente();
             $direcciones = $dircli0->all($this->informe['offset']);
             if ($direcciones) {
                 foreach ($direcciones as $dir) {
                     /// simplemente guardamos para que se eliminen espacios de ciudades, provincias, etc...
                     $dir->save();
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 $this->informe['model'] = 'fin';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'fin':
             break;
     }
     return $last_errores;
 }
 private function reimprimir_ticket()
 {
     $albaran = new albaran_cliente();
     if ($_GET['reticket'] == '') {
         foreach ($albaran->all() as $alb) {
             $alb0 = $alb;
             break;
         }
     } else {
         $alb0 = $albaran->get_by_codigo($_GET['reticket']);
     }
     if ($alb0) {
         $this->imprimir_ticket($alb0, 1, FALSE);
     } else {
         $this->new_error_msg("Ticket no encontrado.");
     }
 }
 private function agrupar_pedidos()
 {
     $continuar = TRUE;
     $albaran = new albaran_cliente();
     $albaran_rellenado = FALSE;
     $art0 = new articulo();
     $num = 0;
     foreach ($this->resultados as $ped) {
         foreach ($ped->get_lineas() as $lin) {
             if (!isset($_POST['idl_' . $num]) or !$continuar) {
             } else {
                 if ($lin->idlinea == intval($_POST['idl_' . $num])) {
                     if (!$albaran_rellenado) {
                         $albaran->codagente = $this->user->codagente;
                         $albaran->codalmacen = $ped->codalmacen;
                         $albaran->coddivisa = $ped->coddivisa;
                         $albaran->tasaconv = $ped->tasaconv;
                         $albaran->codejercicio = $ped->codejercicio;
                         $albaran->codpago = $ped->codpago;
                         $albaran->codserie = $ped->codserie;
                         $albaran->irpf = $ped->irpf;
                         $albaran->cifnif = $this->cliente->cifnif;
                         $albaran->codcliente = $this->cliente->codcliente;
                         $albaran->nombrecliente = $this->cliente->razonsocial;
                         $albaran->apartado = '';
                         $albaran->ciudad = '';
                         $albaran->codpais = $this->empresa->codpais;
                         $albaran->codpostal = '';
                         $albaran->direccion = '';
                         $albaran->provincia = '';
                         foreach ($this->cliente->get_direcciones() as $dir) {
                             if ($dir->domfacturacion) {
                                 $albaran->apartado = $dir->apartado;
                                 $albaran->ciudad = $dir->ciudad;
                                 $albaran->coddir = $dir->id;
                                 $albaran->codpais = $dir->codpais;
                                 $albaran->codpostal = $dir->codpostal;
                                 $albaran->direccion = $dir->direccion;
                                 $albaran->provincia = $dir->provincia;
                                 break;
                             }
                         }
                         if (!$albaran->save()) {
                             $continuar = FALSE;
                             $this->new_error_msg('Error al agrupar el pedido.');
                         }
                         $albaran_rellenado = TRUE;
                     }
                     $linea = new linea_albaran_cliente();
                     $linea->idalbaran = $albaran->idalbaran;
                     $linea->idpedido = $ped->idpedido;
                     $linea->idlineapedido = $lin->idlinea;
                     $linea->referencia = $lin->referencia;
                     $linea->descripcion = $lin->descripcion;
                     $linea->cantidad = floatval($_POST['cantidad_' . $num]);
                     $linea->pvpunitario = $lin->pvpunitario;
                     $linea->codimpuesto = $lin->codimpuesto;
                     $linea->dtopor = $lin->dtopor;
                     $linea->irpf = $lin->irpf;
                     $linea->iva = $lin->iva;
                     $linea->recargo = $lin->recargo;
                     $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                     $linea->pvptotal = $linea->pvpunitario * $linea->cantidad * (100 - $linea->dtopor) / 100;
                     if ($linea->save()) {
                         /// desconamos el stock
                         $articulo = $art0->get($linea->referencia);
                         if ($articulo) {
                             $articulo->sum_stock($albaran->codalmacen, 0 - $linea->cantidad);
                         }
                         $albaran->neto += $linea->pvptotal;
                         $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                         $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                         $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                     } else {
                         $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia);
                         $continuar = FALSE;
                     }
                 }
             }
             $num++;
         }
         if (isset($_POST['aprobado'])) {
             if (in_array($ped->idpedido, $_POST['aprobado'])) {
                 $ped->editable = FALSE;
                 $ped->idalbaran = $albaran->idalbaran;
                 $ped->status = 1;
                 $ped->save();
             }
         }
     }
     if ($continuar) {
         /// redondeamos
         $albaran->neto = round($albaran->neto, FS_NF0);
         $albaran->totaliva = round($albaran->totaliva, FS_NF0);
         $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
         $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
         $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
         if ($albaran->save()) {
             $this->new_message('<a href="' . $albaran->url() . '">' . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
         } else {
             $this->new_error_msg('Error al generar el ' . FS_ALBARAN);
             $albaran->delete();
         }
     } else {
         if (!is_null($albaran->idalbaran)) {
             $albaran->delete();
         }
     }
 }
Ejemplo n.º 23
0
 public function delete()
 {
     if ($this->db->exec("DELETE FROM " . $this->table_name . " WHERE idservicio = " . $this->var2str($this->idservicio) . ";")) {
         if ($this->idalbaran) {
             /**
              * Delegamos la eliminación en la clase correspondiente,
              * que tendrá que hacer más cosas.
              */
             $albaran = new albaran_cliente();
             $alb0 = $albaran->get($this->idalbaran);
             if ($alb0) {
                 $alb0->delete();
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 24
0
 protected function private_core()
 {
     $this->pagado = FALSE;
     $this->pago = new pago();
     $this->pagos = array();
     $this->pendiente = 0;
     if (isset($_GET['delete'])) {
         $pago = $this->pago->get($_GET['delete']);
         if ($pago) {
             if ($pago->delete()) {
                 $this->new_message('Pago eliminado correctamente.');
                 if (!is_null($pago->idfactura)) {
                     $fact0 = new factura_cliente();
                     $factura = $fact0->get($pago->idfactura);
                     if ($factura) {
                         if ($factura->pagada) {
                             $factura->pagada = FALSE;
                             $factura->save();
                         }
                     }
                 }
             } else {
                 $this->new_error_msg('Error al eliminar el pago.');
             }
         } else {
             $this->new_error_msg('Pago no encontrado.');
         }
     } else {
         if (isset($_POST['idpago'])) {
             $pago = $this->pago->get($_POST['idpago']);
             if ($pago) {
                 $pago->fecha = $_POST['fecha'];
                 $pago->importe = floatval($_POST['importe']);
                 $pago->nota = $_POST['nota'];
                 if ($pago->save()) {
                     $this->new_message('Pago modificado correctamente.');
                 } else {
                     $this->new_error_msg('Error al modificar el pago.');
                 }
             } else {
                 $this->new_error_msg('Pago no encontrado.');
             }
         } else {
             if (isset($_POST['importe'])) {
                 if (isset($_REQUEST['factura'])) {
                     $this->pago->fase = 'Factura';
                     $this->pago->idfactura = $_REQUEST['id'];
                 } else {
                     if (isset($_REQUEST['albaran'])) {
                         $this->pago->fase = ucfirst(FS_ALBARAN);
                         $this->pago->idalbaran = $_REQUEST['id'];
                     } else {
                         if (isset($_REQUEST['pedido'])) {
                             $this->pago->fase = ucfirst(FS_PEDIDO);
                             $this->pago->idpedido = $_REQUEST['id'];
                         }
                     }
                 }
                 $this->pago->fecha = $_POST['fecha'];
                 $this->pago->importe = floatval($_POST['importe']);
                 $this->pago->nota = $_POST['nota'];
                 if ($this->pago->save()) {
                     $this->new_message('Pago guardado correctamente.');
                 } else {
                     $this->new_error_msg('Error al guardar el pago.');
                 }
             }
         }
     }
     if (isset($_REQUEST['factura'])) {
         /// esto es la fase de factura
         $fact0 = new factura_cliente();
         $factura = $fact0->get($_REQUEST['id']);
         if ($factura) {
             /// buscamos pagos de la fase albarán
             /// una factura puede ser una agrupación de muchos albaranes
             $idalbaran = NULL;
             foreach ($factura->get_lineas() as $linea) {
                 /// el idalbaran lo tienes en las lineas de la factura
                 if ($linea->idalbaran != $idalbaran) {
                     $idalbaran = $linea->idalbaran;
                     $this->db->exec("UPDATE pagos SET idfactura = " . $fact0->var2str($_REQUEST['id']) . " WHERE idalbaran = " . $fact0->var2str($idalbaran) . ";");
                 }
             }
             $this->pagos = $this->pago->all_from_factura($_REQUEST['id']);
             $this->pendiente = $factura->total;
             foreach ($this->pagos as $i => $value) {
                 $this->pendiente -= $value->importe;
                 $this->pagos[$i]->pendiente = $this->pendiente;
             }
             /// si nos han pagado el total, marcamos la factura como pagada
             if (!$factura->pagada and abs($this->pendiente) < 0.1) {
                 $factura->pagada = TRUE;
                 $factura->save();
             }
             $this->pagado = $factura->pagada;
         }
     } else {
         if (isset($_REQUEST['albaran'])) {
             /// fase de albarán
             $this->pagos = $this->pago->all_from_albaran($_REQUEST['id']);
             /**
              * Falta poner el idalbaran a los pagos de los pedidos que forman este
              * albarán. Si es que hay.
              * Copia esto de la fase de factura.
              */
             $alb0 = new albaran_cliente();
             $albaran = $alb0->get($_REQUEST['id']);
             if ($albaran) {
                 $this->pendiente = $albaran->total;
                 foreach ($this->pagos as $i => $value) {
                     $this->pendiente -= $value->importe;
                     $this->pagos[$i]->pendiente = $this->pendiente;
                 }
                 if (abs($this->pendiente) < 0.1) {
                     $this->pagado = TRUE;
                 }
             }
         } else {
             if (isset($_REQUEST['pedido'])) {
                 /// fose de pedido
                 $this->pagos = $this->pago->all_from_pedido($_REQUEST['id']);
                 $ped0 = new pedido_cliente();
                 $pedido = $ped0->get($_REQUEST['id']);
                 if ($pedido) {
                     $this->pendiente = $pedido->total;
                     foreach ($this->pagos as $i => $value) {
                         $this->pendiente -= $value->importe;
                         $this->pagos[$i]->pendiente = $this->pendiente;
                     }
                     if (abs($this->pendiente) < 0.1) {
                         $this->pagado = TRUE;
                     }
                 }
             }
         }
     }
     $this->share_extensions();
 }
 private function generar_albaran()
 {
     $albaran = new albaran_cliente();
     $albaran->apartado = $this->pedido->apartado;
     $albaran->automatica = TRUE;
     $albaran->cifnif = $this->pedido->cifnif;
     $albaran->ciudad = $this->pedido->ciudad;
     $albaran->codagente = $this->pedido->codagente;
     $albaran->codalmacen = $this->pedido->codalmacen;
     $albaran->codcliente = $this->pedido->codcliente;
     $albaran->coddir = $this->pedido->coddir;
     $albaran->coddivisa = $this->pedido->coddivisa;
     $albaran->tasaconv = $this->pedido->tasaconv;
     $albaran->codpago = $this->pedido->codpago;
     $albaran->codpais = $this->pedido->codpais;
     $albaran->codpostal = $this->pedido->codpostal;
     $albaran->codserie = $this->pedido->codserie;
     $albaran->direccion = $this->pedido->direccion;
     $albaran->editable = TRUE;
     $albaran->neto = $this->pedido->neto;
     $albaran->nombrecliente = $this->pedido->nombrecliente;
     $albaran->observaciones = $this->pedido->observaciones;
     $albaran->provincia = $this->pedido->provincia;
     $albaran->total = $this->pedido->total;
     $albaran->totaliva = $this->pedido->totaliva;
     $albaran->numero2 = $this->pedido->numero2;
     $albaran->irpf = $this->pedido->irpf;
     $albaran->porcomision = $this->pedido->porcomision;
     $albaran->recfinanciero = $this->pedido->recfinanciero;
     $albaran->totalirpf = $this->pedido->totalirpf;
     $albaran->totalrecargo = $this->pedido->totalrecargo;
     /**
      * Obtenemos el ejercicio para la fecha de hoy (puede que
      * no sea el mismo ejercicio que el del pedido, por ejemplo
      * si hemos cambiado de año)
      */
     $eje0 = $this->ejercicio->get_by_fecha($albaran->fecha);
     $albaran->codejercicio = $eje0->codejercicio;
     $regularizacion = new regularizacion_iva();
     if (!$eje0->abierto()) {
         $this->new_error_msg("El ejercicio está cerrado.");
     } else {
         if ($regularizacion->get_fecha_inside($albaran->fecha)) {
             $this->new_error_msg("El IVA de ese periodo ya ha sido regularizado. No se pueden añadir más " . FS_ALBARANES . " en esa fecha.");
         } else {
             if ($albaran->save()) {
                 $continuar = TRUE;
                 $art0 = new articulo();
                 foreach ($this->pedido->get_lineas() as $l) {
                     $n = new linea_albaran_cliente();
                     $n->idpedido = $l->idpedido;
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     $n->dtolineal = $l->dtolineal;
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     if ($n->save()) {
                         /// descontamos del stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             $articulo->sum_stock($albaran->codalmacen, 0 - $l->cantidad);
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($continuar) {
                     $this->pedido->idalbaran = $albaran->idalbaran;
                     $this->pedido->editable = FALSE;
                     if ($this->pedido->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
                     } else {
                         $this->new_error_msg("¡Imposible vincular el " . FS_PEDIDO . " con el nuevo " . FS_ALBARAN . "!");
                         if ($albaran->delete()) {
                             $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                         } else {
                             $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                         }
                     }
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
Ejemplo n.º 26
0
 protected function private_core()
 {
     $this->share_extensions();
     $this->documento = FALSE;
     $this->editable = FALSE;
     if (isset($_REQUEST['albaran'])) {
         $alb0 = new albaran_cliente();
         $this->documento = $alb0->get($_REQUEST['id']);
         if ($this->documento) {
             $this->titulo = FS_ALBARAN . ' ' . $this->documento->codigo;
             $this->lineas = $this->documento->get_lineas();
             $this->editable = $this->documento->ptefactura;
             if (isset($_POST['idlinea'])) {
                 if ($this->editable) {
                     $orden = 1 + count($_POST['idlinea']);
                     foreach ($_POST['idlinea'] as $idl) {
                         foreach ($this->lineas as $lin) {
                             if ($lin->idlinea == $idl) {
                                 $lin->orden = $orden;
                                 $lin->save();
                                 break;
                             }
                         }
                         $orden--;
                     }
                     $this->new_message('Datos guardados correctamente.');
                     $this->lineas = $this->documento->get_lineas();
                 } else {
                     $this->new_error_msg('El documento ya no es editable.');
                 }
             }
         }
     } else {
         if (isset($_REQUEST['factura'])) {
             $fact0 = new factura_cliente();
             $this->documento = $fact0->get($_REQUEST['id']);
             if ($this->documento) {
                 $this->titulo = 'Factura ' . $this->documento->codigo;
                 $this->lineas = $this->documento->get_lineas();
                 $this->editable = TRUE;
                 if (isset($_POST['idlinea'])) {
                     if ($this->editable) {
                         $orden = 1 + count($_POST['idlinea']);
                         foreach ($_POST['idlinea'] as $idl) {
                             foreach ($this->lineas as $lin) {
                                 if ($lin->idlinea == $idl) {
                                     $lin->orden = $orden;
                                     $lin->save();
                                     break;
                                 }
                             }
                             $orden--;
                         }
                         $this->new_message('Datos guardados correctamente.');
                         $this->lineas = $this->documento->get_lineas();
                     } else {
                         $this->new_error_msg('El documento ya no es editable.');
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 27
0
 private function delete_albaran()
 {
     $alb = new albaran_cliente();
     $alb1 = $alb->get($_POST['delete']);
     if ($alb1) {
         /// ¿Actualizamos el stock de los artículos?
         if (isset($_POST['stock'])) {
             $articulo = new articulo();
             foreach ($alb1->get_lineas() as $linea) {
                 $art0 = $articulo->get($linea->referencia);
                 if ($art0) {
                     $art0->sum_stock($alb1->codalmacen, $linea->cantidad);
                     $art0->save();
                 }
             }
         }
         if ($alb1->delete()) {
             $this->new_message(FS_ALBARAN . " " . $alb1->codigo . " borrado correctamente.");
         } else {
             $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
         }
     } else {
         $this->new_error_msg("¡" . FS_ALBARAN . " no encontrado!");
     }
 }
 public function delete()
 {
     if ($this->db->exec("DELETE FROM " . $this->table_name . " WHERE idpedido = " . $this->var2str($this->idpedido) . ";")) {
         if ($this->idalbaran) {
             /**
              * Delegamos la eliminación en la clase correspondiente,
              * que tendrá que hacer más cosas.
              */
             $albaran = new albaran_cliente();
             $alb0 = $albaran->get($this->idalbaran);
             if ($alb0) {
                 $alb0->delete();
             }
         }
         /// modificamos el presupuesto relacionado
         $this->db->exec("UPDATE presupuestoscli SET idpedido = NULL, editable = TRUE WHERE idpedido = " . $this->var2str($this->idpedido) . ";");
         return TRUE;
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 29
0
 private function nuevo_albaran_cliente()
 {
     $continuar = TRUE;
     $cliente = $this->cliente->get($_POST['cliente']);
     if (!$cliente) {
         $this->new_error_msg('Cliente no encontrado.');
         $continuar = FALSE;
     }
     $almacen = $this->almacen->get($_POST['almacen']);
     if ($almacen) {
         $this->save_codalmacen($_POST['almacen']);
     } else {
         $this->new_error_msg('Almacén no encontrado.');
         $continuar = FALSE;
     }
     $eje0 = new ejercicio();
     $ejercicio = $eje0->get_by_fecha($_POST['fecha']);
     if (!$ejercicio) {
         $this->new_error_msg('Ejercicio no encontrado.');
         $continuar = FALSE;
     }
     $serie = $this->serie->get($_POST['serie']);
     if (!$serie) {
         $this->new_error_msg('Serie no encontrada.');
         $continuar = FALSE;
     }
     $forma_pago = $this->forma_pago->get($_POST['forma_pago']);
     if ($forma_pago) {
         $this->save_codpago($_POST['forma_pago']);
     } else {
         $this->new_error_msg('Forma de pago no encontrada.');
         $continuar = FALSE;
     }
     $divisa = $this->divisa->get($_POST['divisa']);
     if (!$divisa) {
         $this->new_error_msg('Divisa no encontrada.');
         $continuar = FALSE;
     }
     $albaran = new albaran_cliente();
     if ($this->duplicated_petition($_POST['petition_id'])) {
         $this->new_error_msg('Petición duplicada. Has hecho doble clic sobre el botón guardar
            y se han enviado dos peticiones. Mira en <a href="' . $albaran->url() . '">' . FS_ALBARANES . '</a>
            para ver si el ' . FS_ALBARAN . ' se ha guardado correctamente.');
         $continuar = FALSE;
     }
     if ($continuar) {
         $albaran->fecha = $_POST['fecha'];
         $albaran->hora = $_POST['hora'];
         $albaran->codalmacen = $almacen->codalmacen;
         $albaran->codejercicio = $ejercicio->codejercicio;
         $albaran->codserie = $serie->codserie;
         $albaran->codpago = $forma_pago->codpago;
         $albaran->coddivisa = $divisa->coddivisa;
         $albaran->tasaconv = $divisa->tasaconv;
         if ($_POST['tasaconv'] != '') {
             $albaran->tasaconv = floatval($_POST['tasaconv']);
         }
         $albaran->codagente = $this->agente->codagente;
         $albaran->numero2 = $_POST['numero2'];
         $albaran->observaciones = $_POST['observaciones'];
         $albaran->irpf = $serie->irpf;
         $albaran->porcomision = $this->agente->porcomision;
         $albaran->codcliente = $cliente->codcliente;
         $albaran->cifnif = $cliente->cifnif;
         $albaran->nombrecliente = $cliente->razonsocial;
         $albaran->ciudad = $_POST['ciudad'];
         $albaran->codpais = $_POST['codpais'];
         $albaran->codpostal = $_POST['codpostal'];
         $albaran->direccion = $_POST['direccion'];
         $albaran->provincia = $_POST['provincia'];
         if ($albaran->save()) {
             $art0 = new articulo();
             $n = floatval($_POST['numlineas']);
             for ($i = 0; $i <= $n; $i++) {
                 if (isset($_POST['referencia_' . $i])) {
                     $linea = new linea_albaran_cliente();
                     $linea->idalbaran = $albaran->idalbaran;
                     $linea->descripcion = $_POST['desc_' . $i];
                     if (!$serie->siniva and $cliente->regimeniva != 'Exento') {
                         $imp0 = $this->impuesto->get_by_iva($_POST['iva_' . $i]);
                         if ($imp0) {
                             $linea->codimpuesto = $imp0->codimpuesto;
                             $linea->iva = floatval($_POST['iva_' . $i]);
                             $linea->recargo = floatval($_POST['recargo_' . $i]);
                         } else {
                             $linea->iva = floatval($_POST['iva_' . $i]);
                             $linea->recargo = floatval($_POST['recargo_' . $i]);
                         }
                     }
                     $linea->irpf = floatval($_POST['irpf_' . $i]);
                     $linea->pvpunitario = floatval($_POST['pvp_' . $i]);
                     $linea->cantidad = floatval($_POST['cantidad_' . $i]);
                     $linea->dtopor = floatval($_POST['dto_' . $i]);
                     $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                     $linea->pvptotal = floatval($_POST['neto_' . $i]);
                     $articulo = $art0->get($_POST['referencia_' . $i]);
                     if ($articulo) {
                         $linea->referencia = $articulo->referencia;
                     }
                     if ($linea->save()) {
                         if ($articulo and isset($_POST['stock'])) {
                             /// descontamos del stock
                             $articulo->sum_stock($albaran->codalmacen, 0 - $linea->cantidad);
                         }
                         $albaran->neto += $linea->pvptotal;
                         $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                         $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                         $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                     } else {
                         $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia);
                         $continuar = FALSE;
                     }
                 }
             }
             if ($continuar) {
                 /// redondeamos
                 $albaran->neto = round($albaran->neto, FS_NF0);
                 $albaran->totaliva = round($albaran->totaliva, FS_NF0);
                 $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
                 $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
                 $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
                 if (abs(floatval($_POST['atotal']) - $albaran->total) >= 0.02) {
                     $this->new_error_msg("El total difiere entre la vista y el controlador (" . $_POST['atotal'] . " frente a " . $albaran->total . "). Debes informar del error.");
                     $albaran->delete();
                 } else {
                     if ($albaran->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . "</a> guardado correctamente.");
                         $this->new_change(ucfirst(FS_ALBARAN) . ' Cliente ' . $albaran->codigo, $albaran->url(), TRUE);
                         if ($_POST['redir'] == 'TRUE') {
                             header('Location: ' . $albaran->url());
                         }
                     } else {
                         $this->new_error_msg("¡Imposible actualizar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                     }
                 }
             } else {
                 if ($albaran->delete()) {
                     $this->new_message(FS_ALBARAN . " eliminado correctamente.");
                 } else {
                     $this->new_error_msg("¡Imposible eliminar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                 }
             }
         } else {
             $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
         }
     }
 }
Ejemplo n.º 30
0
 private function sync()
 {
     $continuar = TRUE;
     $art0 = new articulo();
     $ej0 = new ejercicio();
     $serie0 = new serie();
     $div0 = new divisa();
     foreach (array_reverse($this->pedidos) as $ped) {
         $data = $this->db->select("SELECT * FROM albaranescli WHERE numero2 = " . $art0->var2str($this->order_numero2($ped->order_number)) . ";");
         if (!$data and $continuar and $ped->status == 'completed') {
             $albaran = new albaran_cliente();
             $albaran->numero2 = $this->order_numero2($ped->order_number);
             $albaran->fecha = Date('d-m-Y', strtotime($ped->created_at));
             $albaran->hora = Date('H:i:s', strtotime($ped->created_at));
             $albaran->observaciones = 'Este pedido ha sido importado con la demo de woocommerce, por eso no se ha asignado el cliente.';
             $albaran->cifnif = '';
             $albaran->direccion = '';
             $ejercicio = $ej0->get_by_fecha($albaran->fecha);
             if ($ejercicio) {
                 $albaran->codejercicio = $ejercicio->codejercicio;
                 $serie = $serie0->get($this->setup['wooc_serie']);
                 if ($serie) {
                     $albaran->codserie = $serie->codserie;
                     $albaran->irpf = $serie->irpf;
                     $albaran->codalmacen = $this->setup['wooc_alm'];
                     $divisa = $div0->get($this->empresa->coddivisa);
                     if ($divisa) {
                         $albaran->coddivisa = $divisa->coddivisa;
                         $albaran->tasaconv = $divisa->tasaconv;
                     }
                     $albaran->codpago = $this->empresa->codpago;
                     if ($albaran->save()) {
                         foreach ($ped->line_items as $l) {
                             $linea = new linea_albaran_cliente();
                             $linea->idalbaran = $albaran->idalbaran;
                             $linea->referencia = $l->sku;
                             $linea->descripcion = $l->name;
                             $linea->cantidad = $l->quantity;
                             $linea->irpf = $albaran->irpf;
                             $articulo = $art0->get($l->sku);
                             if ($articulo and !$serie->siniva and $cliente->regimeniva != 'Exento') {
                                 $linea->codimpuesto = $articulo->codimpuesto;
                                 $linea->iva = $articulo->get_iva();
                             }
                             $linea->pvpunitario = 100 * $l->total / $l->quantity / (100 + $linea->iva);
                             $linea->pvptotal = $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                             if ($linea->save()) {
                                 /// descontamos del stock
                                 if ($articulo) {
                                     $articulo->sum_stock($albaran->codalmacen, 0 - $linea->cantidad);
                                 }
                                 $albaran->neto += $linea->pvptotal;
                                 $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                                 $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                                 $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                             } else {
                                 $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia);
                                 $continuar = FALSE;
                             }
                         }
                         /// cupones
                         foreach ($ped->coupon_lines as $l) {
                             $linea = new linea_albaran_cliente();
                             $linea->idalbaran = $albaran->idalbaran;
                             $linea->descripcion = 'Cupón: ' . $l->code;
                             $linea->cantidad = -1;
                             $linea->irpf = $albaran->irpf;
                             if (!$serie->siniva and $cliente->regimeniva != 'Exento') {
                                 $impuesto = $this->impuesto->get($this->setup['wooc_imp']);
                                 if ($impuesto) {
                                     $linea->codimpuesto = $impuesto->codimpuesto;
                                     $linea->iva = $impuesto->iva;
                                 }
                             }
                             $linea->pvpunitario = 100 * floatval($l->amount) / (100 + $linea->iva);
                             $linea->pvptotal = $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                             if ($linea->save()) {
                                 $albaran->neto += $linea->pvptotal;
                                 $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                                 $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                                 $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                             } else {
                                 $this->new_error_msg("¡Imposible guardar la linea del cupón: " . $l->code);
                                 $continuar = FALSE;
                             }
                         }
                         if ($continuar) {
                             /// redondeamos
                             $albaran->neto = round($albaran->neto, FS_NF0);
                             $albaran->totaliva = round($albaran->totaliva, FS_NF0);
                             $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
                             $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
                             $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
                             if ($albaran->save()) {
                                 $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . "</a> guardado correctamente.");
                                 $this->new_change(ucfirst(FS_ALBARAN) . ' Cliente ' . $albaran->codigo, $albaran->url(), TRUE);
                             } else {
                                 $this->new_error_msg("¡Imposible actualizar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                                 $continuar = FALSE;
                             }
                         } else {
                             if ($albaran->delete()) {
                                 $this->new_message(ucfirst(FS_ALBARAN) . " eliminado correctamente.");
                             } else {
                                 $this->new_error_msg("¡Imposible eliminar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                                 $continuar = FALSE;
                             }
                         }
                     } else {
                         $this->new_error_msg('Error al guardar los datos del ' . FS_ALBARAN . ' ' . $ped->order_number);
                         $continuar = FALSE;
                     }
                 } else {
                     $this->new_error_msg('Imposible encontrar una serie para el ' . FS_ALBARAN . ' ' . $ped->order_number);
                     $continuar = FALSE;
                 }
             } else {
                 $this->new_error_msg('Imposible encontrar un ejercicio para el ' . FS_ALBARAN . ' ' . $ped->order_number);
                 $continuar = FALSE;
             }
             break;
         }
     }
     $this->new_advice('Esto es una demo. La versión completa importa todos los pedidos completados, incluyendo clientes y artículos. &nbsp; ' . '<a href="https://www.facturascripts.com/store/producto/plugin-woocommerce/" target="_blank">' . '<span class="glyphicon glyphicon-shopping-cart"></span> comprar la versión completa</a>');
 }