Método que entrega la última acción registrada para el DTE en el registro de compra y venta
@return Arreglo con los datos de la última acción
@author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
@version 2017-08-29
772490
public function getUltimaAccionRCV(\sasco\LibreDTE\FirmaElectronica $Firma)
    {
        list($emisor_rut, $emisor_dv) = explode('-', $this->getEmisor());
        $RCV = new \sasco\LibreDTE\Sii\RegistroCompraVenta($Firma);
        try {
            $eventos = $RCV->listarEventosHistDoc($emisor_rut, $emisor_dv, $this->getTipo(), $this->getFolio());
            return $eventos ? $eventos[count($eventos)-1] : null;
        } catch (\Exception $e) {
            return null;
        }
    }
802193
public function getSignatureBase() {
		$fields = array();

		if ($this->eetStatus !== null) {
			$fields[] = $this->eetStatus;
		}
		if ($this->data) {
			$fields[] = $this->data->getSignatureBase();
		}
		if ($this->verificationMode !== null) {
			$fields[] = $this->verificationMode ? 'true' : 'false';
		}
		if ($this->vatId) {
			$fields[] = $this->vatId;
		}
		if ($this->receiptNumber) {
			$fields[] = $this->receiptNumber;
		}
		if ($this->receiptTime) {
			if (isset($this->rawData['receiptTime']) and $this->rawData['receiptTime']) {
				$fields[] = $this->rawData['receiptTime'];
			} else {
				$fields[] = self::formatTime($this->receiptTime);
			}
		}
		if ($this->evidenceMode !== null) {
			$fields[] = $this->evidenceMode;
		}
		if ($this->uuid !== null) {
			$fields[] = $this->uuid;
		}
		if ($this->sendTime) {
			if (isset($this->rawData['sendTime']) and $this->rawData['sendTime']) {
				$fields[] = $this->rawData['sendTime'];
			} else {
				$fields[] = self::formatTime($this->sendTime);
			}
		}
		if ($this->acceptTime) {
			if (isset($this->rawData['acceptTime']) and $this->rawData['acceptTime']) {
				$fields[] = $this->rawData['acceptTime'];
			} else {
				$fields[] = self::formatTime($this->acceptTime);
			}
		}
		if ($this->bkp) {
			$fields[] = $this->bkp;
		}
		if ($this->pkp) {
			$fields[] = $this->pkp;
		}
		if ($this->fik) {
			$fields[] = $this->fik;
		}
		if ($this->rejectTime) {
			if (isset($this->rawData['rejectTime']) and $this->rawData['rejectTime']) {
				$fields[] = $this->rawData['rejectTime'];
			} else {
				$fields[] = self::formatTime($this->rejectTime);
			}
		}
		if ($this->error) {
			$fields[] = $this->error->getSignatureBase();
		}
		if ($this->warning) {
			foreach ($this->warning as $w) {
				$fields[] = $w->getSignatureBase();
			}
		}

		return implode('|', $fields);
	}
228798
protected function parseTransactionAccount()
    {
        $results = parent::parseTransactionAccount();

        if (empty($results)) {
            $giroMatch = $ibanMatch = [];
            if (preg_match('/^:86:GIRO(.{9})/im', $this->getCurrentTransactionData(), $giroMatch)
                && !empty($giroMatch[1])
            ) {
                $results = $giroMatch[1];
            }

            if (preg_match('!^:86:/.*/IBAN/(.*?)/!m', $this->getCurrentTransactionData(), $ibanMatch)
                && !empty($ibanMatch[1])
            ) {
                $results = $ibanMatch[1];
            }
        }

        return $this->sanitizeAccount($results);
    }
1145107
public function getCopiedTo()
    {
        if (null === $this->_copiedToTokenIds) {
            $this->_copiedToTokenIds = $this->db->fetchPairs(
                    "SELECT gtrp_id_token_new, gtrp_id_token_new
                        FROM gems__token_replacements
                        WHERE gtrp_id_token_old = ?",
                    $this->_tokenId
                    );

            if (! $this->_copiedToTokenIds) {
                $this->_copiedToTokenIds = [];
            }
        }

        return $this->_copiedToTokenIds;
    }
1353699
public function getFieldsTranslations()
    {
        $this->_targetModel->setAlias('gas_name_attended_by', 'gap_id_attended_by');
        $this->_targetModel->setAlias('gas_name_referred_by', 'gap_id_referred_by');
        $this->_targetModel->setAlias('gaa_name', 'gap_id_activity');
        $this->_targetModel->setAlias('gapr_name', 'gap_id_procedure');
        $this->_targetModel->setAlias('glo_name', 'gap_id_location');

        return array(
            'gap_patient_nr'      => 'gr2o_patient_nr',
            'gap_organization_id' => 'gap_id_organization',
            'gap_id_in_source'    => 'gap_id_in_source',
            'gap_admission_time'  => 'gap_admission_time',
            'gap_discharge_time'  => 'gap_discharge_time',
            'gap_admission_code'  => 'gap_code',
            'gap_status_code'     => 'gap_status',
            'gap_attended_by'     => 'gas_name_attended_by',
            'gap_referred_by'     => 'gas_name_referred_by',
            'gap_activity'        => 'gaa_name',
            'gap_procedure'       => 'gapr_name',
            'gap_location'        => 'glo_name',
            'gap_subject'         => 'gap_subject',
            'gap_comment'         => 'gap_comment',

            // Autofill fields - without a source field but possibly set in this translator
            'gap_id_user',

        );
    }
558740
public function actualizarObjetoLdap(){
        if ($this->existe) {
            $dn = $this->entrada['dn'];
            $cambios = array();
            foreach ($this->cambios as $atributos) {
                $cambios[$atributos] = $this->entrada[$atributos];
            }
            return $this->modificarEntradaLdap($dn, $cambios);
        }else{
            $this->configurarErrorLdap('Actualizacion', 'Esa entrada no existe');
            return false;
        }
    }
188986
public function getEntryUri()
    {
        $product = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);

        if ($product->load($this->getEditObjectId())) {
            $seoEncoder = $this->_getEncoder();

            switch ($this->getActCatType()) {
                case 'oxvendor':
                    return $seoEncoder->getArticleVendorUri($product, $this->getEditLang());
                case 'oxmanufacturer':
                    return $seoEncoder->getArticleManufacturerUri($product, $this->getEditLang());
                default:
                    if ($this->getActCatId()) {
                        return $seoEncoder->getArticleUri($product, $this->getEditLang());
                    } else {
                        return $seoEncoder->getArticleMainUri($product, $this->getEditLang());
                    }
            }
        }
    }
649706
private function getDataDeclaration()
    {

        $vars = $this->pgClass->getAttributes()->map(
            function ($column) {
                $dataType = $this->dataTypes[$column->name];

                // initial value
                $initialValue = null;

                // is bool with default
                if( $dataType->isBool( $default ) and is_bool( $default ) ) {
                    $initialValue = $dataType->getDefault();
                }

                $comment = '';

                // primary key
                if( $column->isPrimaryKey() ) {
                    $comment .= 'PK; ';
                }

                // references
                if( count( $references = $column->getReferences() ) ) {
                    $comment .= sprintf( "references %s", $references->implode(', ') );
                }

                // isReferencedBy
                if( count( $isReferencedBy = $column->getIsReferencedBy() ) ) {
                    $comment .= sprintf( "is referenced by %s", $isReferencedBy->implode(', ') );
                }

                // form options
                if( $formOptions = $column->getTags('form') ) {
                    $comment .= "Form options ".json_encode( $formOptions );
                }

                // explode, trim, implode comment
                $comment = implode( ", ", array_map( 'trim', explode( "\n", $comment ) ) );

                return sprintf(
                    "'%s' => %s,%s",
                    $column->name,
                    Php::varExport( $initialValue ),
                    $comment ? " # {$comment}" : ''
                );
            }
        );

        $vars = (new Format($vars))->indent(4);

        $this->class->classComponents[] = new VariableDeclaration(
            'data',
            new Sformatf( <<<'PHP'
/**
 * Columns defined in %s
 * @var array
 */
protected $data = array(
%s
);
PHP
                , $this->pgClass->getFullyQualifiedName()
                , $vars
            )
        );

        return $this;

    }
1321532
public function getPeriods2()
  {
    $periods = array();

    $this->Period->byOrganizationWithYear($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($Period) use (&$periods)
    {
      // array_push($periods, array('value'=> $Period->id, 'label' => $this->Lang->get('decima-accounting::period-management.' . $Period->month) . ' ' . $Period->year->year));
      array_push($periods, array('value'=> $Period->id, 'label' => $this->Lang->get('decima-accounting::period-management.' . $Period->month) . ' ' . $Period->year));
    });

    return $periods;
  }
617273
public function getVatValue()
    {
        if ($this->isNettoMode()) {
            $dVatValue = $this->getNettoPrice() * $this->getVat() / 100;
        } else {
            $dVatValue = $this->getBruttoPrice() * $this->getVat() / (100 + $this->getVat());
        }

        return \OxidEsales\Eshop\Core\Registry::getUtils()->fRound($dVatValue);
    }
1060123
public function getInstallmentConfig()
    {
        $installmentConfig = $this->_dataObjectFactory->create();

        $maxInstallmentQty = $this->getMaximumInstallmentQuantity();
        $installmentConfig->maximumInstallmentQty = $maxInstallmentQty;
        $installmentConfig->minimumInstallmentAmount = $this->getMinimumInstallmentAmount();
        $installmentConfig->interestRate = $this->getInterestRate();

        $installments = [];

        # Looping through all possible installment values
        for ($curInstallment = 1; ($curInstallment <= 12 && $curInstallment <= $maxInstallmentQty); $curInstallment++) {
            if ($curInstallment === 1) {
                # If this is a one time payment, we use the current value and only one installment, no interest
                $installments[$curInstallment] = $this->_dataObjectFactory->create();
                $installments[$curInstallment]->interestRate = $this->getInterestRateForInstallment($curInstallment);
                $installments[$curInstallment]->numberInstallments = 1;
                $installments[$curInstallment]->minimumAmountNoInterest = null;

                continue;
            } else {
                $installments[$curInstallment] = $this->_dataObjectFactory->create();
                $installments[$curInstallment]->interestRate = $this->getInterestRateForInstallment($curInstallment);
                $installments[$curInstallment]->numberInstallments = $curInstallment;
                $installments[$curInstallment]->minimumAmountNoInterest =
                    $this->getMinimumAmountNoInterest($curInstallment);
            }
        }
        $installmentConfig->installments = $installments;

        return $installmentConfig;
    }
381587
public function index() {
        $this->layout = 'Stats.default';
        $this->elementMenu = 'Stats.menu';
        
        // por default ordenar por sumatoria de dinero vendido
        $conditions['order'] = array('ventas DESC',"cant DESC");
        if ( !empty( $this->request->query ) && $this->request->query['cant_o_tot'] == 1 ) {
            // ordenado por cantidad de unidades vendidas            
            $conditions['order'] = array("cant DESC", 'ventas DESC');
        }

        

        $this->Prg->commonProcess();
        $conds = $this->DetalleComanda->parseCriteria( $this->Prg->parsedParams() );
        $conditions['conditions'] = $conds;
        $conditions['conditions']['Mesa.deleted'] = 0;


		$this->DetalleComanda->Producto->recursive = -1;        
        $conditions['group'] = array('Producto.id', 'Producto.name');        
        $conditions['joins'] = array(
            array(
                'table' => 'detalle_comandas',
                'alias' => 'DetalleComanda',
                'type' => 'left',
                'conditions' => 'Producto.id = DetalleComanda.producto_id',
            ),
            array(
                'table' => 'comandas',
                'alias' => 'Comanda',
                'type' => 'left',
                'conditions' => 'Comanda.id = DetalleComanda.comanda_id',
            ),
            array(
                'table' => 'mesas',
                'alias' => 'Mesa',
                'type' => 'left',
                'conditions' => 'Mesa.id = Comanda.mesa_id',
            ), 
        );
        $conditions['fields'] = array(
            'Producto.name', 
            'sum(DetalleComanda.cant-DetalleComanda.cant_eliminada)*Producto.precio as "ventas"',
            'Producto.precio', 
            'sum(DetalleComanda.cant-DetalleComanda.cant_eliminada) as "cant"',
            );


        if ( empty($this->request->query['desde']) ) {
            $desde = $this->DetalleComanda->find('first', array(
                'order' => array('DetalleComanda.created' => 'ASC')
                ));
            $desde = $desde['DetalleComanda']['created'];
        } else {
            $desde = $this->request->query['desde'];
        }

        if ( empty($this->request->query['hasta']) ) {
            $hasta = $this->DetalleComanda->find('first', array(
                'order' => array('DetalleComanda.created' => 'DESC')
                ));
            $hasta = $hasta['DetalleComanda']['created'];
        } else {
            $hasta = $this->request->query['hasta'];
        }
                                

        $comandas  = $this->DetalleComanda->Producto->find('all', $conditions);
        $cantTotal = 0;
        $ventasTotal = 0;
        foreach ($comandas as $c) {
            $cantTotal += $c[0]['cant'];
            $ventasTotal += $c[0]['ventas'];
        }

        if ( !empty( $this->request->query ) && $this->request->query['cant_o_tot'] == 1 ) {
            $this->request->data['DetalleComanda']['cant_o_tot']  = 1;
        }

        $this->set('categorias', $this->DetalleComanda->Producto->Categoria->generateTreeList());
        $this->set('productos', $this->DetalleComanda->Producto->find('list', array('order' => 'name')));
        $this->set('tags', $this->DetalleComanda->Producto->Tag->find('list', array('order' => 'name')));
		$this->set(compact('comandas', 'cantTotal', 'ventasTotal','tags', 'desde', 'hasta'));
	}
886293
public function iniciar()
    {
        if ($this->iniciado) {
            return true;
        }

        if (!$this->adaptador->abrir($this->nombre)) {
            throw new \RuntimeException('Hubo un error inicializando el adaptador de sesión.');
        }

        if (!$this->id) {
            $this->id = $this->generarId();
        }

        $this->datos = $this->adaptador->leer($this->id);

        return $this->iniciado = true;
    }
249956
public function getLongDesc()
    {
        if (isset($this->oxcategories__oxlongdesc) && $this->oxcategories__oxlongdesc instanceof \OxidEsales\Eshop\Core\Field) {
            /** @var \OxidEsales\Eshop\Core\UtilsView $oUtilsView */
            $oUtilsView = \OxidEsales\Eshop\Core\Registry::getUtilsView();
            return $oUtilsView->parseThroughSmarty($this->oxcategories__oxlongdesc->getRawValue(), $this->getId() . $this->getLanguage(), null, true);
        }
    }
1099079
public function getResumenManual()
    {
        $manual = [];
        if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) {
            $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'];
            if (!isset($totales[0]))
                $totales = [$totales];
            foreach ($totales as $total) {
                if (isset($total['TpoDoc']) and in_array($total['TpoDoc'], [35, 38, 48])) {
                    $manual[$total['TpoDoc']] = array_merge($this->total_default, $total);
                }
            }
        }
        return $manual;
    }
868141
public function insertar()
    {
        // Preparamos variables a usar
        $bd = Aplicacion::instanciar()->obtenerBdRelacional();
        $parametros = [];
        $llavePrimaria = (array) $this->__llavePrimaria;

        // Hacemos recorrido de campos
        foreach ($this->__campos as $campo => $meta) {

            // Verificamos si el campo es llave
            $esLlave = in_array($campo, $llavePrimaria);

            // Validamos requerimiento del campo
            if (!empty($meta['requerido']) && $this->campoVacio($campo)) {
                if (!($esLlave && $this->__llavePrimariaAutonum)) {
                    throw new \RuntimeException("Falta el campo requerido '{$campo}'.");
                }
            }

            // Agregamos campo existente a los parametros de inserción
            if (isset($this->{$campo})) {
                $parametros[$campo . '|' . $meta['tipo']] = $this->{$campo};
            }
        }

        if ($bd->insertar($this->__nombreTabla, $parametros)->ejecutar()) {
            if ($this->__llavePrimariaAutonum && !is_array($this->__llavePrimaria)) {
                $this->{$this->__llavePrimaria} = $bd->ultimoIdInsertado();
            }

            return true;
        }

        return false;
    }
470854
public function getAgenciaCodigoBeneficiario()
    {
        $agencia = $this->getAgenciaDv() !== null ? $this->getAgencia() . '-' . $this->getAgenciaDv() : $this->getAgencia();

        if ($this->getContaDv() !== null && strlen($this->getContaDv()) == 1) {
            $conta = substr($this->getConta(), 0, -1) . '-' .substr($this->getConta(), -1).$this->getContaDv();
        } elseif ($this->getContaDv() !== null && strlen($this->getContaDv()) == 2) {
            $conta = substr($this->getConta(), 0, -1) . '-' .substr($this->getConta(), -1).$this->getContaDv();
        } else {
            $conta = $this->getConta();
        }

        return $agencia . ' / ' . $conta;
    }