protected function private_core() { $this->ppage = $this->page->get('ventas_clientes'); $this->agente = new agente(); $this->cuenta_banco = new cuenta_banco_cliente(); $this->divisa = new divisa(); $this->forma_pago = new forma_pago(); $this->grupo = new grupo_clientes(); $this->pais = new pais(); $this->serie = new serie(); $this->ncf_tipo = new ncf_tipo(); $this->ncf_entidad_tipo = new ncf_entidad_tipo(); /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); /// cargamos el cliente $cliente = new cliente(); $this->cliente = FALSE; if (isset($_POST['codcliente'])) { $this->cliente = $cliente->get($_POST['codcliente']); } else { if (isset($_GET['cod'])) { $this->cliente = $cliente->get($_GET['cod']); } } $this->ncf_cliente_tipo = $this->ncf_entidad_tipo->get($this->empresa->id, $this->cliente->codcliente, 'CLI'); if ($this->cliente) { $this->page->title = $this->cliente->codcliente; /// ¿Hay que hacer algo más? if (isset($_GET['delete_cuenta'])) { $cuenta = $this->cuenta_banco->get($_GET['delete_cuenta']); if ($cuenta) { if ($cuenta->delete()) { $this->new_message('Cuenta bancaria eliminada correctamente.'); } else { $this->new_error_msg('Imposible eliminar la cuenta bancaria.'); } } else { $this->new_error_msg('Cuenta bancaria no encontrada.'); } } else { if (isset($_GET['delete_dir'])) { $dir = new direccion_cliente(); $dir0 = $dir->get($_GET['delete_dir']); if ($dir0) { if ($dir0->delete()) { $this->new_message('Dirección eliminada correctamente.'); } else { $this->new_error_msg('Imposible eliminar la dirección.'); } } else { $this->new_error_msg('Dirección no encontrada.'); } } else { if (isset($_POST['coddir'])) { $dir = new direccion_cliente(); if ($_POST['coddir'] != '') { $dir = $dir->get($_POST['coddir']); } $dir->apartado = $_POST['apartado']; $dir->ciudad = $_POST['ciudad']; $dir->codcliente = $this->cliente->codcliente; $dir->codpais = $_POST['pais']; $dir->codpostal = $_POST['codpostal']; $dir->descripcion = $_POST['descripcion']; $dir->direccion = $_POST['direccion']; $dir->domenvio = isset($_POST['direnvio']); $dir->domfacturacion = isset($_POST['dirfact']); $dir->provincia = $_POST['provincia']; if ($dir->save()) { $this->new_message("Dirección guardada correctamente."); } else { $this->new_message("¡Imposible guardar la dirección!"); } } else { if (isset($_POST['iban'])) { if (isset($_POST['codcuenta'])) { $cuentab = $this->cuenta_banco->get($_POST['codcuenta']); } else { $cuentab = new cuenta_banco_cliente(); $cuentab->codcliente = $_POST['codcliente']; } $cuentab->descripcion = $_POST['descripcion']; $cuentab->iban = $_POST['iban']; $cuentab->swift = $_POST['swift']; $cuentab->principal = isset($_POST['principal']); $cuentab->fmandato = NULL; if (isset($_POST['fmandato'])) { if ($_POST['fmandato'] != '') { $cuentab->fmandato = $_POST['fmandato']; } } if ($cuentab->save()) { $this->new_message('Cuenta bancaria guardada correctamente.'); } else { $this->new_error_msg('Imposible guardar la cuenta bancaria.'); } } else { if (isset($_POST['codcliente'])) { $this->cliente->nombre = $_POST['nombre']; $this->cliente->razonsocial = $_POST['razonsocial']; $this->cliente->tipoidfiscal = $_POST['tipoidfiscal']; $this->cliente->cifnif = $_POST['cifnif']; $this->cliente->telefono1 = $_POST['telefono1']; $this->cliente->telefono2 = $_POST['telefono2']; $this->cliente->fax = $_POST['fax']; $this->cliente->web = $_POST['web']; $this->cliente->email = $_POST['email']; $this->cliente->observaciones = $_POST['observaciones']; $this->cliente->codpago = $_POST['codpago']; $this->cliente->coddivisa = $_POST['coddivisa']; $this->cliente->regimeniva = $_POST['regimeniva']; $this->cliente->recargo = isset($_POST['recargo']); $this->cliente->debaja = isset($_POST['debaja']); $this->cliente->personafisica = isset($_POST['personafisica']); $this->cliente->codserie = NULL; if ($_POST['codserie'] != '') { $this->cliente->codserie = $_POST['codserie']; } $this->cliente->codagente = NULL; if ($_POST['codagente'] != '') { $this->cliente->codagente = $_POST['codagente']; } $this->cliente->codgrupo = NULL; if ($_POST['codgrupo'] != '') { $this->cliente->codgrupo = $_POST['codgrupo']; } if (isset($_POST['tipo_comprobante'])) { $continue = TRUE; $tipo_comprobante = \filter_input(INPUT_POST, 'tipo_comprobante'); if ($tipo_comprobante == '01' and strlen($this->cliente->cifnif) < 9) { $this->new_error_msg("¡Imposible actualizar información de NCF para el cliente, por favor corrija primero la Cédula o RNC asignados!"); } else { $ncf_entidad_tipo = new ncf_entidad_tipo(); $ncf_entidad_tipo->idempresa = $this->empresa->id; $ncf_entidad_tipo->entidad = \filter_input(INPUT_POST, 'codcliente'); $ncf_entidad_tipo->tipo_entidad = 'CLI'; $ncf_entidad_tipo->tipo_comprobante = $tipo_comprobante; $ncf_entidad_tipo->usuario_creacion = $this->user->nick; $ncf_entidad_tipo->fecha_creacion = \Date('d-m-Y H:i:s'); $ncf_entidad_tipo->usuario_modificacion = $this->user->nick; $ncf_entidad_tipo->fecha_modificacion = \Date('d-m-Y H:i:s'); $ncf_entidad_tipo->estado = TRUE; if (!$ncf_entidad_tipo->save()) { $this->new_error_msg("¡Imposible actualizar información de NCF para Cliente " . $ncf_entidad_tipo->entidad . "!"); } else { $this->ncf_cliente_tipo = $this->ncf_entidad_tipo->get($this->empresa->id, \filter_input(INPUT_POST, 'codcliente'), 'CLI'); } } } if ($this->cliente->save()) { $this->new_message("Datos del cliente modificados correctamente."); $this->propagar_cifnif(); } else { $this->new_error_msg("¡Imposible modificar los datos del cliente!"); } } } } } } } else { $this->new_error_msg("¡Cliente no encontrado!", 'error', FALSE, FALSE); } }
protected function private_core() { /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); $this->cliente = new cliente(); $this->grupo = new grupo_clientes(); $this->pais = new pais(); $this->serie = new serie(); $this->tarifa = new tarifa(); $this->tarifas = $this->tarifa->all(); $this->ncf_tipo = new ncf_tipo(); $this->ncf_entidad_tipo = new ncf_entidad_tipo(); /// cargamos la configuración $fsvar = new fs_var(); $this->nuevocli_setup = $fsvar->array_get(array('nuevocli_cifnif_req' => 0, 'nuevocli_direccion' => 1, 'nuevocli_direccion_req' => 0, 'nuevocli_codpostal' => 1, 'nuevocli_codpostal_req' => 0, 'nuevocli_pais' => 0, 'nuevocli_pais_req' => 0, 'nuevocli_provincia' => 1, 'nuevocli_provincia_req' => 0, 'nuevocli_ciudad' => 1, 'nuevocli_ciudad_req' => 0, 'nuevocli_telefono1' => 0, 'nuevocli_telefono1_req' => 0, 'nuevocli_telefono2' => 0, 'nuevocli_telefono2_req' => 0, 'nuevocli_codgrupo' => ''), FALSE); if (isset($_GET['delete_grupo'])) { $grupo = $this->grupo->get($_GET['delete_grupo']); if ($grupo) { if ($grupo->delete()) { $this->new_message('Grupo eliminado correctamente.'); } else { $this->new_error_msg('Imposible eliminar el grupo.'); } } else { $this->new_error_msg('Grupo no encontrado.'); } } else { if (isset($_POST['codgrupo'])) { $grupo = $this->grupo->get($_POST['codgrupo']); if (!$grupo) { $grupo = new grupo_clientes(); $grupo->codgrupo = $_POST['codgrupo']; } $grupo->nombre = $_POST['nombre']; $grupo->codtarifa = NULL; if ($_POST['codtarifa'] != '---') { $grupo->codtarifa = $_POST['codtarifa']; } if ($grupo->save()) { $this->new_message('Grupo guardado correctamente.'); } else { $this->new_error_msg('Imposible guardar el grupo.'); } } else { if (isset($_GET['delete'])) { $cliente = $this->cliente->get($_GET['delete']); if ($cliente) { if (FS_DEMO) { $this->new_error_msg('En el modo demo no se pueden eliminar clientes. Otros usuarios podrían necesitarlos.'); } else { if ($cliente->delete()) { $this->new_message('Cliente eliminado correctamente.'); } else { $this->new_error_msg('Ha sido imposible eliminar el cliente.'); } } } else { $this->new_error_msg('Cliente no encontrado.'); } } else { if (isset($_POST['cifnif'])) { $cliente = new cliente(); $cliente->codcliente = $cliente->get_new_codigo(); $cliente->nombre = $_POST['nombre']; $cliente->razonsocial = $_POST['nombre']; $cliente->tipoidfiscal = $_POST['tipoidfiscal']; $cliente->cifnif = $_POST['cifnif']; $cliente->personafisica = isset($_POST['personafisica']); if (isset($_POST['scodgrupo'])) { if ($_POST['scodgrupo'] != '') { $cliente->codgrupo = $_POST['scodgrupo']; } } if (isset($_POST['telefono1'])) { $cliente->telefono1 = $_POST['telefono1']; } if (isset($_POST['telefono2'])) { $cliente->telefono2 = $_POST['telefono2']; } if ($cliente->save()) { if (\filter_input(INPUT_POST, 'tipo_comprobante') != '') { $ncf_entidad_tipo = new ncf_entidad_tipo(); $ncf_entidad_tipo->idempresa = $this->empresa->id; $ncf_entidad_tipo->entidad = $cliente->codcliente; $ncf_entidad_tipo->tipo_entidad = 'CLI'; $ncf_entidad_tipo->tipo_comprobante = \filter_input(INPUT_POST, 'tipo_comprobante'); $ncf_entidad_tipo->estado = TRUE; $ncf_entidad_tipo->usuario_creacion = $this->user->nick; $ncf_entidad_tipo->fecha_creacion = Date('d-m-Y H:i:s'); $ncf_entidad_tipo->save(); } $dircliente = new direccion_cliente(); $dircliente->codcliente = $cliente->codcliente; $dircliente->codpais = $this->empresa->codpais; $dircliente->provincia = $this->empresa->provincia; $dircliente->ciudad = $this->empresa->ciudad; $dircliente->descripcion = 'Principal'; if (isset($_POST['pais'])) { $dircliente->codpais = $_POST['pais']; } if (isset($_POST['provincia'])) { $dircliente->provincia = $_POST['provincia']; } if (isset($_POST['ciudad'])) { $dircliente->ciudad = $_POST['ciudad']; } if (isset($_POST['codpostal'])) { $dircliente->codpostal = $_POST['codpostal']; } if (isset($_POST['direccion'])) { $dircliente->direccion = $_POST['direccion']; } if ($dircliente->save()) { if ($this->empresa->contintegrada) { /// forzamos la creación de la subcuenta $cliente->get_subcuenta($this->empresa->codejercicio); } /// redireccionamos a la página del cliente header('location: ' . $cliente->url()); } else { $this->new_error_msg("¡Imposible guardar la dirección del cliente!"); } } else { $this->new_error_msg("¡Imposible guardar los datos del cliente!"); } } } } } $this->offset = 0; if (isset($_GET['offset'])) { $this->offset = intval($_GET['offset']); } $this->ciudad = ''; if (isset($_REQUEST['ciudad'])) { $this->ciudad = $this->empresa->no_html($_REQUEST['ciudad']); } $this->provincia = ''; if (isset($_REQUEST['provincia'])) { $this->provincia = $this->empresa->no_html($_REQUEST['provincia']); } $this->codpais = ''; if (isset($_REQUEST['codpais'])) { $this->codpais = $_REQUEST['codpais']; } $this->codgrupo = ''; if (isset($_REQUEST['bcodgrupo'])) { $this->codgrupo = $_REQUEST['bcodgrupo']; } $this->orden = 'nombre ASC'; if (isset($_REQUEST['orden'])) { $this->orden = $_REQUEST['orden']; } $this->nocifnif = isset($_REQUEST['nocifnif']); $this->debaja = isset($_REQUEST['debaja']); $this->buscar(); $this->grupos = $this->grupo->all(); }
protected function private_core() { $this->agencia = new agencia_transporte(); $this->cliente = new cliente(); $this->cliente_s = FALSE; $this->direccion = FALSE; $this->fabricante = new fabricante(); $this->familia = new familia(); $this->impuesto = new impuesto(); $this->results = array(); $this->grupo = new grupo_clientes(); $this->pais = new pais(); $this->ncf_tipo = new ncf_tipo(); $this->ncf_rango = new ncf_rango(); $this->ncf_entidad_tipo = new ncf_entidad_tipo(); $this->ncf_ventas = new ncf_ventas(); /// cargamos la configuración $fsvar = new fs_var(); $this->nuevocli_setup = $fsvar->array_get(array('nuevocli_cifnif_req' => 0, 'nuevocli_direccion' => 0, 'nuevocli_direccion_req' => 0, 'nuevocli_codpostal' => 0, 'nuevocli_codpostal_req' => 0, 'nuevocli_pais' => 0, 'nuevocli_pais_req' => 0, 'nuevocli_provincia' => 0, 'nuevocli_provincia_req' => 0, 'nuevocli_ciudad' => 0, 'nuevocli_ciudad_req' => 0, 'nuevocli_telefono1' => 0, 'nuevocli_telefono1_req' => 0, 'nuevocli_telefono2' => 0, 'nuevocli_telefono2_req' => 0, 'nuevocli_codgrupo' => ''), FALSE); if (isset($_REQUEST['tipo'])) { $this->tipo = $_REQUEST['tipo']; } else { foreach ($this->tipos_a_guardar() as $t) { $this->tipo = $t['tipo']; break; } } if (isset($_REQUEST['buscar_cliente'])) { $this->buscar_cliente(); } else { if (isset($_REQUEST['datoscliente'])) { $this->datos_cliente(); } else { if (isset($_REQUEST['new_articulo'])) { $this->new_articulo(); } else { if ($this->query != '') { $this->new_search(); } else { if (isset($_POST['referencia4precios'])) { $this->get_precios_articulo(); } else { if (isset($_POST['referencia4combi'])) { $this->get_combinaciones_articulo(); } else { if (isset($_POST['cliente'])) { $this->cliente_s = $this->cliente->get($_POST['cliente']); /** * Nuevo cliente */ if (isset($_POST['nuevo_cliente'])) { if ($_POST['nuevo_cliente'] != '') { $this->cliente_s = FALSE; if ($_POST['nuevo_cifnif'] != '') { $this->cliente_s = $this->cliente->get_by_cifnif($_POST['nuevo_cifnif']); if ($this->cliente_s) { $this->new_advice('Ya existe un cliente con ese ' . FS_CIFNIF . '. Se ha seleccionado.'); } } if (!$this->cliente_s) { $this->cliente_s = new cliente(); $this->cliente_s->codcliente = $this->cliente_s->get_new_codigo(); $this->cliente_s->nombre = $this->cliente_s->razonsocial = $_POST['nuevo_cliente']; $this->cliente_s->tipoidfiscal = $_POST['nuevo_tipoidfiscal']; $this->cliente_s->cifnif = $_POST['nuevo_cifnif']; $this->cliente_s->personafisica = isset($_POST['personafisica']); if (isset($_POST['codgrupo'])) { if ($_POST['codgrupo'] != '') { $this->cliente_s->codgrupo = $_POST['codgrupo']; } } if (isset($_POST['nuevo_telefono1'])) { $this->cliente_s->telefono1 = $_POST['nuevo_telefono1']; } if (isset($_POST['nuevo_telefono2'])) { $this->cliente_s->telefono2 = $_POST['nuevo_telefono2']; } if ($this->cliente_s->save()) { if (isset($_POST['tipo_comprobante'])) { $ncf_entidad_tipo = new ncf_entidad_tipo(); $ncf_entidad_tipo->idempresa = $this->empresa->id; $ncf_entidad_tipo->entidad = $this->cliente_s->codcliente; $ncf_entidad_tipo->tipo_entidad = 'CLI'; $ncf_entidad_tipo->tipo_comprobante = \filter_input(INPUT_POST, 'tipo_comprobante'); $ncf_entidad_tipo->usuario_creacion = $this->user->nick; $ncf_entidad_tipo->fecha_creacion = \Date('d-m-Y H:i:s'); $ncf_entidad_tipo->usuario_modificacion = $this->user->nick; $ncf_entidad_tipo->fecha_modificacion = \Date('d-m-Y H:i:s'); $ncf_entidad_tipo->estado = TRUE; if (!$ncf_entidad_tipo->save()) { $this->new_error_msg("¡Imposible actualizar información de NCF para Cliente " . $ncf_entidad_tipo->entidad . "!"); } else { $this->ncf_cliente_tipo = $this->ncf_entidad_tipo->get($this->empresa->id, $this->cliente_s->codcliente, 'CLI'); } } if ($this->empresa->contintegrada) { /// forzamos crear la subcuenta $this->cliente_s->get_subcuenta($this->empresa->codejercicio); } $dircliente = new direccion_cliente(); $dircliente->codcliente = $this->cliente_s->codcliente; $dircliente->codpais = $this->empresa->codpais; $dircliente->provincia = $this->empresa->provincia; $dircliente->ciudad = $this->empresa->ciudad; if (isset($_POST['nuevo_pais'])) { $dircliente->codpais = $_POST['nuevo_pais']; } if (isset($_POST['nuevo_provincia'])) { $dircliente->provincia = $_POST['nuevo_provincia']; } if (isset($_POST['nuevo_ciudad'])) { $dircliente->ciudad = $_POST['nuevo_ciudad']; } if (isset($_POST['nuevo_codpostal'])) { $dircliente->codpostal = $_POST['nuevo_codpostal']; } if (isset($_POST['nuevo_direccion'])) { $dircliente->direccion = $_POST['nuevo_direccion']; } if ($dircliente->save()) { $this->new_message('Cliente agregado correctamente.'); } } else { $this->new_error_msg("¡Imposible guardar la dirección del cliente!"); } } } } if ($this->cliente_s) { foreach ($this->cliente_s->get_direcciones() as $dir) { if ($dir->domfacturacion) { $this->direccion = $dir; break; } } } if (isset($_POST['codagente'])) { $agente = new agente(); $this->agente = $agente->get($_POST['codagente']); } else { $this->agente = $this->user->get_agente(); } $this->almacen = new almacen(); $this->serie = new serie(); $this->forma_pago = new forma_pago(); $this->divisa = new divisa(); if (isset($_POST['tipo'])) { if ($_POST['tipo'] == 'albaran') { $this->nuevo_albaran_cliente(); } else { if ($_POST['tipo'] == 'factura') { $this->nueva_factura_cliente(); } else { if ($_POST['tipo'] == 'presupuesto' and class_exists('presupuesto_cliente')) { $this->nuevo_presupuesto_cliente(); } else { if ($_POST['tipo'] == 'pedido' and class_exists('pedido_cliente')) { $this->nuevo_pedido_cliente(); } } } } /// si el cliente no tiene cifnif nos guardamos el que indique if ($this->cliente_s->cifnif == '') { $this->cliente_s->cifnif = $_POST['cifnif']; $this->cliente_s->save(); } /// ¿Guardamos la dirección como nueva? if ($_POST['coddir'] == 'nueva') { $this->direccion = new direccion_cliente(); $this->direccion->codcliente = $this->cliente_s->codcliente; $this->direccion->codpais = $_POST['codpais']; $this->direccion->provincia = $_POST['provincia']; $this->direccion->ciudad = $_POST['ciudad']; $this->direccion->codpostal = $_POST['codpostal']; $this->direccion->direccion = $_POST['direccion']; $this->direccion->apartado = $_POST['apartado']; $this->direccion->save(); } else { if ($_POST['envio_coddir'] == 'nueva') { $this->direccion = new direccion_cliente(); $this->direccion->codcliente = $this->cliente_s->codcliente; $this->direccion->codpais = $_POST['envio_codpais']; $this->direccion->provincia = $_POST['envio_provincia']; $this->direccion->ciudad = $_POST['envio_ciudad']; $this->direccion->codpostal = $_POST['envio_codpostal']; $this->direccion->direccion = $_POST['envio_direccion']; $this->direccion->apartado = $_POST['envio_apartado']; $this->direccion->domfacturacion = FALSE; $this->direccion->domenvio = TRUE; $this->direccion->save(); } } } } } } } } } } }