private function nuevo_recibo() { $factura = new factura_proveedor(); $this->factura = $factura->get($_POST['idfactura']); if ($this->factura) { $recibo = new recibo_proveedor(); $recibo->cifnif = $this->factura->cifnif; $recibo->coddivisa = $this->factura->coddivisa; $recibo->tasaconv = $this->factura->tasaconv; $recibo->codpago = $this->factura->codpago; $recibo->codproveedor = $this->factura->codproveedor; $recibo->codserie = $this->factura->codserie; $recibo->estado = 'Emitido'; $recibo->fecha = $_POST['fecha']; $recibo->fechav = $_POST['fechav']; $recibo->idfactura = $this->factura->idfactura; $recibo->importe = floatval($_POST['importe']); $recibo->nombreproveedor = $this->factura->nombre; $recibo->numero = $recibo->new_numero($recibo->idfactura); $recibo->codigo = $this->factura->codigo . '-' . sprintf('%02s', $recibo->numero); $cbp = new cuenta_banco_proveedor(); foreach ($cbp->all_from_proveedor($recibo->codproveedor) as $cuenta) { if (is_null($recibo->codcuenta) or $cuenta->principal) { $recibo->codcuenta = $cuenta->codcuenta; $recibo->iban = $cuenta->iban; $recibo->swift = $cuenta->swift; } } if ($recibo->save()) { $this->new_message('Recibo creado correctamente.'); header('Location: ' . $recibo->url()); } else { $this->new_error_msg('Error al guardar el recibo.'); } } else { $this->new_error_msg('Factura no encontrada.'); } }