public function viajes_now()
 {
     if (!isset($_GET['p'])) {
         $_GET['p'] = 1;
     }
     if (!isset($_GET['q'])) {
         $_GET['q'] = "";
     }
     if (!isset($_GET['criterio'])) {
         $_GET['criterio'] = "cronograma.origen";
     }
     $obj = new viaje();
     $objc = new caja();
     $data = array();
     $data['verif'] = $objc->verificar_caja();
     $data['data'] = $obj->viajes_now($_GET['q'], $_GET['p'], $_GET['criterio']);
     //Recupero los viajes del dia de HOY
     $data['query'] = $_GET['q'];
     $data['pag'] = $this->Pagination(array('rows' => $data['data']['rowspag'], 'url' => 'index.php?controller=venta&action=viajes_now', 'query' => $_GET['q']));
     $cols = array("CODIGO", "ORIGEN", "DESTINO", "H.SALIDA", "H.LLEGADA", "BUSS", "FECHA");
     $opt = array("cronograma.origen" => "ORIGEN", "cronograma.destino" => "destino", "cronograma.horasalida" => "Hora Salida");
     $data['grilla'] = $this->grilla("viaje", $cols, $data['data']['rows'], $opt, $data['pag'], false, false, false, false);
     $view = new View();
     $view->setData($data);
     $view->setTemplate('../view/venta/_viajes.php');
     $view->setLayout('../template/Layout.php');
     $view->render();
 }
 public function indexAction()
 {
     if (!$this->idcaja) {
         $this->new_error_msg("Caja incorrecta");
     }
     $this->caja = caja::get($this->idcaja);
     if ($this->caja) {
         $this->recibos = $this->caja->findRecibos();
     } else {
         $this->recibos = array();
     }
 }
Esempio n. 3
0
 public function __construct($c = FALSE)
 {
     parent::__construct('cajas', 'plugins/facturacion_base/');
     if (!isset(self::$agentes)) {
         self::$agentes = array();
     }
     if ($c) {
         $this->id = $this->intval($c['id']);
         $this->fs_id = $this->intval($c['fs_id']);
         $this->fecha_inicial = Date('d-m-Y H:i:s', strtotime($c['f_inicio']));
         $this->dinero_inicial = floatval($c['d_inicio']);
         if (is_null($c['f_fin'])) {
             $this->fecha_fin = NULL;
         } else {
             $this->fecha_fin = Date('d-m-Y H:i:s', strtotime($c['f_fin']));
         }
         $this->dinero_fin = floatval($c['d_fin']);
         $this->codagente = $c['codagente'];
         $this->tickets = intval($c['tickets']);
         $this->ip = NULL;
         if (isset($c['ip'])) {
             $this->ip = $c['ip'];
         }
         foreach (self::$agentes as $ag) {
             if ($ag->codagente == $this->codagente) {
                 $this->agente = $ag;
                 break;
             }
         }
         if (!isset($this->agente)) {
             $ag = new agente();
             $this->agente = $ag->get($this->codagente);
             self::$agentes[] = $this->agente;
         }
     } else {
         $this->id = NULL;
         $this->fs_id = NULL;
         $this->codagente = NULL;
         $this->fecha_inicial = Date('d-m-Y H:i:s');
         $this->dinero_inicial = 0;
         $this->fecha_fin = NULL;
         $this->dinero_fin = 0;
         $this->tickets = 0;
         $this->ip = NULL;
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $this->ip = $_SERVER['REMOTE_ADDR'];
         }
         $this->agente = NULL;
     }
 }
 private function cerrar_caja()
 {
     $this->caja->fecha_fin = Date('d-m-Y H:i:s');
     if ($this->caja->save()) {
         if ($this->terminal) {
             $this->terminal->add_linea_big("\nCIERRE DE CAJA:\n");
             $this->terminal->add_linea("Empleado: " . $this->user->codagente . " " . $this->agente->get_fullname() . "\n");
             $this->terminal->add_linea("Caja: " . $this->caja->fs_id . "\n");
             $this->terminal->add_linea("Fecha inicial: " . $this->caja->fecha_inicial . "\n");
             $this->terminal->add_linea("Dinero inicial: " . $this->show_precio($this->caja->dinero_inicial, FALSE, FALSE) . "\n");
             $this->terminal->add_linea("Fecha fin: " . $this->caja->show_fecha_fin() . "\n");
             $this->terminal->add_linea("Dinero fin: " . $this->show_precio($this->caja->dinero_fin, FALSE, FALSE) . "\n");
             $this->terminal->add_linea("Diferencia: " . $this->show_precio($this->caja->diferencia(), FALSE, FALSE) . "\n");
             $this->terminal->add_linea("Tickets: " . $this->caja->tickets . "\n\n");
             $this->terminal->add_linea("Dinero pesado:\n\n\n");
             $this->terminal->add_linea("Observaciones:\n\n\n\n");
             $this->terminal->add_linea("Firma:\n\n\n\n\n\n\n");
             /// encabezado común para los tickets
             $this->terminal->add_linea_big($this->terminal->center_text($this->empresa->nombre, 16) . "\n");
             $this->terminal->add_linea($this->terminal->center_text($this->empresa->lema) . "\n\n");
             $this->terminal->add_linea($this->terminal->center_text($this->empresa->direccion . " - " . $this->empresa->ciudad) . "\n");
             $this->terminal->add_linea($this->terminal->center_text("CIF: " . $this->empresa->cifnif));
             $this->terminal->cortar_papel();
             $this->terminal->add_linea("\n\n");
             $this->terminal->add_linea($this->terminal->center_text($this->empresa->horario) . "\n");
             $this->terminal->abrir_cajon();
             $this->terminal->save();
             /// recargamos la página
             header('location: ' . $this->url() . '&terminal=' . $this->terminal->id);
         } else {
             /// recargamos la página
             header('location: ' . $this->url());
         }
     } else {
         $this->new_error_msg("¡Imposible cerrar la caja!");
     }
 }
 protected function private_core()
 {
     $this->share_extensions();
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->articulo = new articulo();
     $this->cliente = new cliente();
     $this->cliente_s = FALSE;
     $this->familia = new familia();
     $this->impuesto = new impuesto();
     $this->results = array();
     if (isset($_REQUEST['buscar_cliente'])) {
         $this->buscar_cliente();
     } else {
         if (isset($_REQUEST['datoscliente'])) {
             $this->datos_cliente();
         } else {
             if ($this->query != '') {
                 $this->new_search();
             } else {
                 if (isset($_REQUEST['referencia4precios'])) {
                     $this->get_precios_articulo();
                 } else {
                     $this->agente = $this->user->get_agente();
                     $this->almacen = new almacen();
                     $this->divisa = new divisa();
                     $this->ejercicio = new ejercicio();
                     $this->forma_pago = new forma_pago();
                     $this->serie = new serie();
                     $this->imprimir_descripciones = isset($_COOKIE['imprimir_desc']);
                     $this->imprimir_observaciones = isset($_COOKIE['imprimir_obs']);
                     if ($this->agente) {
                         $this->caja = FALSE;
                         $this->terminal = FALSE;
                         $caja = new caja();
                         $terminal0 = new terminal_caja();
                         foreach ($caja->all_by_agente($this->agente->codagente) as $cj) {
                             if ($cj->abierta()) {
                                 $this->caja = $cj;
                                 $this->terminal = $terminal0->get($cj->fs_id);
                                 break;
                             }
                         }
                         if (!$this->caja) {
                             if (isset($_POST['terminal'])) {
                                 $this->terminal = $terminal0->get($_POST['terminal']);
                                 if (!$this->terminal) {
                                     $this->new_error_msg('Terminal no encontrado.');
                                 } else {
                                     if ($this->terminal->disponible()) {
                                         $this->caja = new caja();
                                         $this->caja->fs_id = $this->terminal->id;
                                         $this->caja->codagente = $this->agente->codagente;
                                         $this->caja->dinero_inicial = floatval($_POST['d_inicial']);
                                         $this->caja->dinero_fin = floatval($_POST['d_inicial']);
                                         if ($this->caja->save()) {
                                             $this->new_message("Caja iniciada con " . $this->show_precio($this->caja->dinero_inicial));
                                         } else {
                                             $this->new_error_msg("¡Imposible guardar los datos de caja!");
                                         }
                                     } else {
                                         $this->new_error_msg('El terminal ya no está disponible.');
                                     }
                                 }
                             } else {
                                 if (isset($_GET['terminal'])) {
                                     $this->terminal = $terminal0->get($_GET['terminal']);
                                     if ($this->terminal) {
                                         $this->terminal->abrir_cajon();
                                         $this->terminal->save();
                                     } else {
                                         $this->new_error_msg('Terminal no encontrado.');
                                     }
                                 }
                             }
                         }
                         if ($this->caja) {
                             if (isset($_POST['cliente'])) {
                                 $this->cliente_s = $this->cliente->get($_POST['cliente']);
                             } else {
                                 if ($this->terminal) {
                                     $this->cliente_s = $this->cliente->get($this->terminal->codcliente);
                                 }
                             }
                             if (!$this->cliente_s) {
                                 foreach ($this->cliente->all() as $cli) {
                                     $this->cliente_s = $cli;
                                     break;
                                 }
                             }
                             if (isset($_GET['abrir_caja'])) {
                                 $this->abrir_caja();
                             } else {
                                 if (isset($_GET['cerrar_caja'])) {
                                     $this->cerrar_caja();
                                 } else {
                                     if (isset($_POST['cliente'])) {
                                         if (intval($_POST['numlineas']) > 0) {
                                             $this->nueva_factura_cliente();
                                         }
                                     } else {
                                         if (isset($_GET['reticket'])) {
                                             $this->reimprimir_ticket();
                                         }
                                     }
                                 }
                             }
                         } else {
                             $this->results = $terminal0->disponibles();
                         }
                     } else {
                         $this->new_error_msg('No tienes un <a href="' . $this->user->url() . '">agente asociado</a>
            a tu usuario, y por tanto no puedes hacer tickets.');
                     }
                 }
             }
         }
     }
 }
 /**
  * @param asiento $asiento
  * @param divisa $divisa
  * @param fs_controller $controller
  *
  * @return bool Status de la importacion de las cajas
  */
 public static function importar_caja(asiento $asiento, divisa $divisa, fs_controller $controller)
 {
     $art = new articulo();
     $continuar = true;
     /** @var caja[] $cajas_importadas */
     $cajas_importadas = array();
     foreach ($_POST['cajas'] as $idcaja) {
         $caja = caja::get($idcaja);
         // Lo primero que tiene que haber en el asiento es una linea con el monto de la caja importada
         // Cuando importe muchas, lo que va a haber es una sola linea con el total de cajas
         contabilidad_asiento::add_partida($asiento, $divisa, '110101001', array('debe' => $caja->dinero_fin, 'haber' => 0, 'comprobante' => '<a hreh="' . $caja->url() . '">Caja #' . $caja->id . '</a>,'));
         foreach ($caja->get_recibos() as $recibo) {
             $factura = $recibo->getFactura();
             // Obtengo las lineas de la factura
             $lineas = $factura->get_lineas();
             // Después de acuerdo a la forma de pago del recibo tengo que agregar el pago a cada una de las cuentas
             switch ($recibo->codpago) {
                 case 'CONT':
                     // TODO: Cuando es de contado, a que cuenta va?
                     break;
                 case 'DBT MACRO':
                     contabilidad_asiento::add_partida($asiento, $divisa, '110103001', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                     break;
                 case 'DBT S. RIO':
                 case 'CTA CTE':
                     contabilidad_asiento::add_partida($asiento, $divisa, '110103006', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                     break;
                 case 'TRF':
                 case 'CHQ':
                 case 'DEP':
                     contabilidad_asiento::add_partida($asiento, $divisa, '110103003', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                     break;
                 case 'TC':
                 case 'TD':
                     contabilidad_asiento::add_partida($asiento, $divisa, '1102010000', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                     break;
                 default:
                     $controller->new_error_msg("La forma de pago no está configurada para ser importada!");
                     break;
             }
             // Después de eso viene la parte "compleja":
             // Si la factura del recibo está pagada
             if ($factura->pagada) {
                 // El monto total de la factura es igual al del recibo?
                 if ($recibo->importe === $factura->total) {
                     // tomamos todos los articulos y los importamos de acuerdo a la subcuenta de venta
                     // que está declarada en cada articulo (este es el caso "normal", como por ejemplo
                     // el de las COMIDAS_PERSONAL
                     foreach ($lineas as $linea) {
                         $articulo = $art->get($linea->referencia);
                         // Si no hay articulo tengo un grave problema
                         if ($articulo && $articulo->codsubcuentaven) {
                             contabilidad_asiento::add_partida($asiento, $divisa, $articulo->codsubcuentaven, array('debe' => 0, 'haber' => $linea->pvptotal, 'comprobante' => ''));
                         } else {
                             $controller->new_error_msg('La factura: <a href="' . $factura->url() . '">#' . $factura->numero . '</a> tiene un un artículo inexistente: ' . $linea->referencia . 'o el artículo no tiene configurada la cuenta a la que deve ser cargada');
                         }
                     }
                 } else {
                     // Si la factura está paga pero los totales difieren
                     // Eso quiere decir que los pagos están dispersos entre varias cajas, por lo que tengo que
                     // importar solamente el monto del recibo
                     // si el artículo que tiene soalemente es una reserva
                     if (count($lineas) === 1 && $lineas[0]->referencia === 'Reserva') {
                         // se agrega la partida a la subcuenta 210101003
                         contabilidad_asiento::add_partida($asiento, $divisa, '210101003', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                         contabilidad_asiento::add_partida($asiento, $divisa, '410101001', array('debe' => 0, 'haber' => $factura->total, 'comprobante' => ''));
                     } else {
                         // No se que hacer en estos casos
                         $controller->new_error_msg('La factura <a href="' . $factura->url() . '">#' . $factura->numero . '</a> está paga  pero el importe está distribuido y contiene otros articulos que no' . ', por lo que no puede ser importada en un asiento contable por favor ignore la caja #' . $caja->id);
                         $continuar = false;
                     }
                 }
             } else {
                 // Si la factura no está paga y el artículo es una reserva
                 // entonces los recibos van a la subcuenta 210101003
                 if (count($lineas) === 1 && $lineas[0]->referencia === 'Reserva') {
                     contabilidad_asiento::add_partida($asiento, $divisa, '210101003', array('debe' => 0, 'haber' => $recibo->importe, 'comprobante' => ''));
                 } else {
                     //No se que hacer en estos casos
                     $controller->new_error_msg('La factura <a href="' . $factura->url() . '">#' . $factura->numero . '</a> no está paga y contiene otros articulos que no son una reserva, por lo que no ' . ' puede ser importada en un asiento contable  por favor ignore la caja #' . $caja->id);
                     $continuar = false;
                 }
             }
         }
         if ($continuar) {
             $cajas_importadas[] = $caja;
         }
     }
     // Si todas las cajas fueron importadas correctamente
     if ($continuar) {
         // Guardo las partidas asociadas al asiento en la BBDD
         foreach (contabilidad_asiento::$partidas as $subcuenta => $partida) {
             // Creamos una nueva partida
             $part = new partida();
             // Cargamos los valores en la partida
             foreach ($partida as $name => $value) {
                 if (property_exists($part, $name)) {
                     $part->{$name} = $value;
                 }
             }
             $part->referencia = 'Caja importada el ' . date('Y-m-d H:i:s') . ' por ' . $controller->user->get_agente()->get_fullname();
             // Al guardar la partida se actualiza automáticamente los valores de la subcuenta
             // Y el monto del asiento
             if ($part->save()) {
                 $continuar = $continuar && true;
             } else {
                 $continuar = false;
             }
         }
         if ($continuar) {
             foreach ($cajas_importadas as $caja) {
                 $caja->setIdAsiento($asiento->idasiento);
                 if (!$caja->save()) {
                     $controller->new_error_msg("Error al actualizar la caja #" . $caja->id);
                     $continuar = $continuar && true;
                 } else {
                     $continuar = false;
                 }
             }
             if ($continuar) {
                 $controller->new_message('Cajas importada correctamente');
             } else {
                 $controller->new_error_msg('Hubo algún error al vincular el asiento con las cajas');
             }
         } else {
             // Creo que acá tendría que hacer rollback de toda la transacción
             $controller->new_error_msg("Error al guardar una partida al asiento");
         }
     } else {
         $controller->new_error_msg("Error al importar cajas");
     }
     return $continuar;
 }
 protected function private_core()
 {
     $this->agente = new agente();
     $this->factura = new factura_cliente();
     $this->huecos = array();
     $this->serie = new serie();
     $this->caja = caja::get_caja_activa();
     $this->check_caja();
     $this->mostrar = 'todo';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
         setcookie('ventas_fac_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['ventas_fac_mostrar'])) {
             $this->mostrar = $_COOKIE['ventas_fac_mostrar'];
         }
     }
     $this->offset = 0;
     if (isset($_REQUEST['offset'])) {
         $this->offset = intval($_REQUEST['offset']);
     }
     $this->order = 'fecha DESC';
     if (isset($_GET['order'])) {
         if ($_GET['order'] == 'fecha_desc') {
             $this->order = 'fecha DESC';
         } else {
             if ($_GET['order'] == 'fecha_asc') {
                 $this->order = 'fecha ASC';
             } else {
                 if ($_GET['order'] == 'vencimiento_desc') {
                     $this->order = 'vencimiento DESC';
                 } else {
                     if ($_GET['order'] == 'vencimiento_asc') {
                         $this->order = 'vencimiento ASC';
                     }
                 }
             }
         }
         setcookie('ventas_fac_order', $this->order, time() + FS_COOKIES_EXPIRE);
     } else {
         if (isset($_COOKIE['ventas_fac_order'])) {
             $this->order = $_COOKIE['ventas_fac_order'];
         }
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_REQUEST['buscar_cliente'])) {
             $this->buscar_cliente();
         } else {
             if (isset($_GET['ref'])) {
                 $this->template = 'extension/ventas_facturas_articulo';
                 $articulo = new articulo();
                 $this->articulo = $articulo->get($_GET['ref']);
                 $linea = new linea_factura_cliente();
                 $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
             } else {
                 $this->share_extension();
                 $this->huecos = $this->factura->huecos();
                 $this->cliente = FALSE;
                 $this->codagente = '';
                 $this->codserie = '';
                 $this->desde = '';
                 $this->hasta = '';
                 $this->num_resultados = '';
                 $this->total_resultados = '';
                 $this->total_resultados_comision = 0;
                 $this->total_resultados_txt = '';
                 if (isset($_GET['delete'])) {
                     $this->delete_factura();
                 } else {
                     if (!isset($_GET['mostrar']) and (isset($_REQUEST['codagente']) or isset($_REQUEST['codcliente']))) {
                         /**
                          * si obtenermos un codagente o un codcliente pasamos direcatemente
                          * a la pestaña de búsqueda, a menos que tengamos un mostrar, que
                          * entonces nos indica donde tenemos que estar.
                          */
                         $this->mostrar = 'buscar';
                     }
                     if (isset($_REQUEST['codcliente'])) {
                         if ($_REQUEST['codcliente'] != '') {
                             $cli0 = new cliente();
                             $this->cliente = $cli0->get($_REQUEST['codcliente']);
                         }
                     }
                     if (isset($_REQUEST['codagente'])) {
                         $this->codagente = $_REQUEST['codagente'];
                     }
                     if (isset($_REQUEST['codserie'])) {
                         $this->codserie = $_REQUEST['codserie'];
                         $this->desde = $_REQUEST['desde'];
                         $this->hasta = $_REQUEST['hasta'];
                     }
                 }
                 /// añadimos segundo nivel de ordenación
                 $order2 = '';
                 if (substr($this->order, -4) == 'DESC') {
                     $order2 = ', codigo DESC';
                 } else {
                     $order2 = ', codigo ASC';
                 }
                 if ($this->mostrar == 'sinpagar') {
                     $this->resultados = $this->factura->all_sin_pagar($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     if ($this->offset == 0) {
                         $this->total_resultados = 0;
                         $this->total_resultados_txt = 'Suma total de esta página:';
                         foreach ($this->resultados as $fac) {
                             $this->total_resultados += $fac->total;
                         }
                     }
                 } else {
                     if ($this->mostrar == 'buscar') {
                         $this->buscar($order2);
                     } else {
                         $this->resultados = $this->factura->all($this->offset, FS_ITEM_LIMIT, $this->order . $order2);
                     }
                 }
             }
         }
     }
 }
 protected function private_core()
 {
     $this->template = 'ajax/importar_caja';
     $obj = new caja();
     $this->cajas = $obj->findCajasSinAsiento();
 }
 public function cerrarCajaAction()
 {
     if ($this->user->admin) {
         $caja2 = caja::get($_GET['cerrar']);
         if ($caja2 && !$caja2->fecha_fin) {
             $caja2->setEdit();
             $caja2->fecha_fin = date('d-m-Y H:i:s');
             if ($caja2->save()) {
                 $this->new_message("Caja cerrada correctamente.");
                 $this->indexAction();
             } else {
                 $this->new_error_msg("¡Imposible cerrar la caja!");
             }
         } else {
             $this->new_error_msg("Caja no encontrada o caja ya cerrada.");
         }
     } else {
         $this->new_error_msg("Tienes que ser administrador para poder cerrar cajas.");
     }
     $this->indexAction();
 }
 private function importar_cajas($eje0, $div0)
 {
     foreach ($_POST['cajas'] as $idcaja) {
         $caja = caja::get($idcaja);
         $pagos = $caja->findRecibos();
         foreach ($pagos as $pago) {
             var_dump($pago);
         }
         $caja->setIdAsiento($this->asiento->idasiento);
         if ($caja->save() && $this->asiento->save()) {
             $this->new_message('<a href="">Caja #' . $idcaja . '</a> importada correctamente');
         } else {
             $this->new_error_msg('Error al importar la caja #' . $idcaja);
         }
     }
 }
Esempio n. 11
0
    $db = new fs_mysql();
} else {
    require_once 'base/fs_postgresql.php';
    $db = new fs_postgresql();
}
require_once 'base/fs_model.php';
require_model('caja.php');
if ($db->connect()) {
    if (isset($_GET['remote-printer'])) {
        if (FS_PRINTER == 'remote-printer') {
            /**
             * Añadimos un poquito de seguridad.
             * Comprobamos que la IP desde la que se quiere imprimir corresponda
             * con la del usuario que ha abierto la caja.
             */
            $caja = new caja();
            $caja0 = $caja->get_last_from_this_server();
            if ($caja0 and isset($_SERVER['REMOTE_ADDR'])) {
                if ($caja0->ip == $_SERVER['REMOTE_ADDR'] or is_null($caja0->ip)) {
                    if (file_exists('tmp/' . FS_TMP_NAME . 'remote-printer.txt')) {
                        echo file_get_contents('tmp/' . FS_TMP_NAME . 'remote-printer.txt');
                        unlink('tmp/' . FS_TMP_NAME . 'remote-printer.txt');
                    }
                } else {
                    echo 'ERROR 3';
                }
            }
        } else {
            echo 'ERROR 2';
        }
    } else {
Esempio n. 12
0
 /**
  * @param array $data
  * @return caja
  */
 public function setValues($data = array())
 {
     if (!isset(self::$agentes)) {
         self::$agentes = array();
     }
     $this->id = isset($data['id']) ? $this->intval($data['id']) : null;
     $this->fs_id = isset($data['fs_id']) ? $this->intval($data['fs_id']) : null;
     $this->fecha_inicial = isset($data['f_inicio']) ? date(self::DATE_FORMAT_FULL, strtotime($data['f_inicio'])) : date(self::DATE_FORMAT_FULL);
     $this->dinero_inicial = isset($data['d_inicio']) ? floatval($data['d_inicio']) : 0;
     $this->fecha_fin = isset($data['f_fin']) && !is_null($data['f_fin']) ? date(self::DATE_FORMAT_FULL, strtotime($data['f_fin'])) : null;
     $this->dinero_fin = isset($data['d_fin']) && floatval($data['d_fin']) > 0.0 ? $data['d_fin'] : $this->dinero_inicial;
     $this->codagente = isset($data['codagente']) ? $data['codagente'] : null;
     $this->tickets = isset($data['tickets']) ? intval($data['tickets']) : 0;
     $this->ip = isset($data['ip']) ? $data['ip'] : null;
     $this->idasiento = isset($data['idasiento']) ? intval($data['idasiento']) : null;
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $this->ip = $_SERVER['REMOTE_ADDR'];
     }
     foreach (self::$agentes as $ag) {
         if ($ag && $ag->codagente == $this->codagente) {
             $this->agente = $ag;
             break;
         }
     }
     if (!isset($this->agente)) {
         $ag = new agente();
         $this->agente = $ag->get($this->codagente);
         self::$agentes[] = $this->agente;
     }
     return $this;
 }