public function generar_asiento_faltante(&$faltante, $ejercicio)
 {
     $ok = FALSE;
     $this->asiento = FALSE;
     $tipo = $faltante->estado;
     $conductor0 = new distribucion_conductores();
     $subcuenta_conductor = FALSE;
     $concepto = $tipo == 'pendiente' ? "Faltante " : "Pago Faltante ";
     $conductor = $conductor0->get($faltante->idempresa, $faltante->conductor);
     if ($conductor) {
         $subcuenta_conductor = $this->get_subcuenta($ejercicio);
     }
     if (!$subcuenta_conductor) {
         $eje0 = $this->ejercicio->get($ejercicio);
         return "No se ha podido generar una subcuenta para el conductor <a href='" . $eje0->url() . "'>¿Has importado los datos del ejercicio?</a>";
         if (!$this->soloasiento) {
             return "Aun así el <a href='" . $faltante->url() . "'>faltante</a> se ha generado correctamente, pero sin asiento contable.";
         }
     } else {
         $asiento = new asiento();
         $asiento->codejercicio = $ejercicio;
         $asiento->concepto = $concepto . $faltante->idrecibo . " - " . $faltante->nombreconductor;
         $asiento->documento = $faltante->idrecibo;
         $asiento->editable = FALSE;
         $asiento->fecha = $faltante->fecha;
         $asiento->importe = $faltante->importe;
         $asiento->tipodocumento = $concepto . ' Liquidacion';
         if ($asiento->save()) {
             $asiento_correcto = TRUE;
             $subcuenta = new subcuenta();
             $partida0 = new partida();
             $partida0->idasiento = $asiento->idasiento;
             $partida0->concepto = $asiento->concepto;
             $partida0->idsubcuenta = $subcuenta_conductor->idsubcuenta;
             $partida0->codsubcuenta = $subcuenta_conductor->codsubcuenta;
             if ($tipo == 'pendiente') {
                 $partida0->debe = $faltante->importe;
             } elseif ($tipo == 'pagado') {
                 $partida0->haber = $faltante->importe;
             }
             $partida0->coddivisa = $faltante->coddivisa;
             $partida0->tasaconv = 1;
             $partida0->codserie = NULL;
             if (!$partida0->save()) {
                 $asiento_correcto = FALSE;
             }
             if ($asiento_correcto) {
                 $faltante->idasiento = $asiento->idasiento;
                 $faltante->idsubcuenta = $partida0->idsubcuenta;
                 $faltante->codcuenta = $partida0->codsubcuenta;
                 if ($faltante->save()) {
                     $ok = TRUE;
                     $this->asiento = $asiento;
                 } else {
                     return "¡Imposible añadir el asiento al faltante!";
                 }
             } else {
                 if ($asiento->delete()) {
                     return "El asiento se ha borrado.";
                 } else {
                     return "¡Imposible borrar el asiento!";
                 }
             }
         } else {
             return "¡Imposible guardar el asiento!";
         }
     }
     return $ok;
 }
Пример #2
0
 public function private_core()
 {
     $this->share_extensions();
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $this->almacen = new almacen();
     $this->distrib_transporte = new distribucion_transporte();
     $this->distrib_lineastransporte = new distribucion_lineastransporte();
     $this->distrib_facturas = new distribucion_ordenescarga_facturas();
     $this->factura_cliente = new factura_cliente();
     $this->faltante = new distribucion_faltantes();
     $this->subcuentas_faltantes = new distribucion_subcuentas_faltantes();
     $this->asiento = new asiento();
     $this->ejercicio = new ejercicio();
     $this->helper_transportes = new helper_transportes();
     $this->conductores = new distribucion_conductores();
     $type = \filter_input(INPUT_GET, 'type');
     $mostrar = \filter_input(INPUT_GET, 'mostrar');
     $cliente = \filter_input(INPUT_GET, 'codcliente');
     $offset = \filter_input(INPUT_GET, 'offset');
     $this->mostrar = "todo";
     $this->offset = isset($offset) ? $offset : 0;
     if (isset($mostrar)) {
         $this->mostrar = $mostrar;
         setcookie('distrib_transporte_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
     } elseif (isset($_COOKIE['distrib_transporte_mostrar'])) {
         $this->mostrar = $_COOKIE['distrib_transporte_mostrar'];
     }
     if (isset($_REQUEST['codalmacen'])) {
         if ($_REQUEST['codalmacen'] != '') {
             $this->codalmacen = $_REQUEST['codalmacen'];
         }
     }
     if (isset($cliente) and !empty($cliente)) {
         $cli0 = new cliente();
         $codcliente = $cli0->get($cliente);
     }
     $this->cliente = isset($codcliente) ? $codcliente : FALSE;
     if (isset($_REQUEST['conductor'])) {
         if ($_REQUEST['conductor'] != '') {
             $cli0 = new distribucion_conductores();
             $this->conductor = $cli0->get($this->empresa->id, $_REQUEST['conductor']);
         }
     }
     $this->num_resultados = 0;
     if ($type === 'imprimir-transporte') {
         $this->imprimir_transporte();
     } elseif ($type == 'confirmar-transporte') {
         $this->confirmar_transporte();
     } elseif ($type == 'eliminar-transporte') {
         $this->eliminar_transporte();
     } elseif ($type == 'liquidar-transporte') {
         $this->liquidar_transporte();
     } elseif ($type == 'guardar-liquidacion') {
         $this->guardar_liquidacion();
     } elseif ($type == 'imprimir-liquidacion') {
         $this->imprimir_liquidacion();
     } elseif ($type == 'pagar-factura') {
         $this->pagar_factura();
     } elseif ($type == 'extornar-factura') {
         $this->extornar_factura();
     } elseif ($type == 'crear-faltante') {
         $this->crear_faltante();
     }
     if ($this->mostrar == 'todo') {
         $this->resultados = $this->distrib_transporte->all($this->empresa->id, $this->offset);
     } elseif ($this->mostrar == 'por_despachar') {
         $this->resultados = $this->distrib_transporte->all_pendientes($this->empresa->id, 'despachado', $this->offset);
     } elseif ($this->mostrar == 'por_liquidar') {
         $this->resultados = $this->distrib_transporte->all_pendientes($this->empresa->id, 'liquidado', $this->offset);
     } elseif ($this->mostrar == 'buscar') {
         setcookie('distrib_transportes_mostrar', $this->mostrar, time() + FS_COOKIES_EXPIRE);
         $this->buscador();
     }
     if (isset($_REQUEST['buscar_conductor'])) {
         $this->buscar_conductor();
     }
     if (isset($_REQUEST['desde'])) {
         $this->desde = $_REQUEST['desde'];
         $this->hasta = $_REQUEST['hasta'];
     }
 }