✏️ 正在编辑: SimuladorTabelaFator.php
路径:
/srv/systems_dir/yuppiecred-bkp/application/forms/SimuladorTabelaFator.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Form_SimuladorTabelaFator extends Core_Form { public function init() { $this->setName('f_simulador_tabela_fator'); $this->setAction($this->getView()->url(array( 'action' => 'calcular-fator' ))); $this->addElement('select', 'banco', array( 'label' => 'Banco:', 'multiOptions' => Core_Combos::getBancosOptions() )); $select = new Zend_Form_Element_Select('convenio'); $select->setLabel('Convênio:') ->addMultiOptions(Core_Combos::getConveniosOptions()) ->setAttrib('onchange', "populateComboTabelaFatores(this.id, 'tabela', 'banco', null,'avulso')"); $this->addElement($select); $select = new Zend_Form_Element_Select('tabela'); $select->setLabel('Tabela:') ->setAttrib('class', 'tabela') ->setAttrib('onchange', "populateFieldsSimulator(this.id)") ->setRegisterInArrayValidator(false); $this->addElement($select); $this->addElement('text', 'parcela', array( 'label' => 'Parcela / margem:', 'size' => 10, 'onkeypress' => "mascara(this, mvalor)" )); $this->addElement('text', 'valor_emprestimo', array( 'label' => 'Valor Empréstimo:', 'size' => 15, 'onkeypress' => "mascara(this, mvalor)" )); $this->addElement('text', 'prazo', array( 'label' => 'Prazo:', 'required' => true, 'size' => 15, 'onkeypress' => 'mascara(this, soNumeros)' )); $this->addElement('text', 'fator', array( 'label' => 'Fator:', 'size' => 7, 'onkeypress' => "mascara(this, mfator)" )); $this->addElement('text', 'saldo_devedor', array( 'label' => 'Saldo devedor:', 'size' => 15, 'onkeypress' => "mascara(this, mvalor)" )); $this->addElement('submit', 'btn_calcular', array( 'label' => 'Calcular' )); $this->addDisplayGroup(array( 'banco', 'convenio', 'tabela', 'dia' ), 'simulacao_tabela', array( 'legend' => 'Simulação Tabela' )); $this->addDisplayGroup(array( 'valor_emprestimo', 'parcela','prazo', 'fator', 'saldo_devedor'), 'simulacao_avulsa', array( 'legend' => 'Simulação Avulsa' )); $this->addDisplayGroup(array('btn_calcular'), 'buttons'); } protected function _getSelect($column) { $dbFatores = new Model_DbTable_TabelaFator(); $select = $dbFatores->select()->from($dbFatores, array( $column )) ->group($column); return $select; } protected function _getBancos() { $options = array( '' => '' ); $select = $this->_getSelect('banco_id'); $dbBanco = new Model_DbTable_Banco(); $values = $dbBanco->fetchAll("ativo = 1 AND id IN({$select})", 'nome ASC'); if( count($values) > 0 ){ foreach ( $values as $value ) { $options[$value['id']] = $value['nome']; } } return $options; } protected function _getConvenios() { $options = array( '' => '' ); $select = $this->_getSelect('convenio_id'); $db = new Model_DbTable_Convenio(); $values = $db->fetchAll("id IN({$select})", 'nome ASC'); if( count($values) > 0 ){ foreach ( $values as $value ) { $options[$value['id']] = $value['nome']; } } return $options; } public function calculaFator($margem) { $values = $this->getValues(); $banco = (int) $values['banco']; $tabela = (int) $values['tabela']; $convenio = (int) $values['convenio']; $dt = new Zend_Date($values['dia']); $dia = $dt->get('dd'); $vlMargem = str_replace(array( '.', ',' ), array( '', '.' ), $margem); $tabelaFator = new Model_DbTable_TabelaFator(); $where = "convenio_id = $convenio"; if( $banco ){ $where .= " AND banco_id = $banco"; } if( $tabela ){ $where .= " AND tabela_id = $tabela"; } if( $dia ){ $where .= " AND dia = $dia"; } else { $dia = Zend_Date::now()->get('dd'); $where .= " AND (dia IS NULL OR dia = $dia)"; } $fatores = $tabelaFator->fetchAll($where); if( !$fatores ){ return null; } $result = array(); foreach ( $fatores as $fator ) { $result[] = array( 'parcela' => $vlMargem, 'prazo' => $fator->prazo, 'dia' => $fator->dia, 'emprestimo' => $vlMargem / $fator->fator ); } return reset($result); } /** * Calcula, pela tabela price, o valor da parcela de um contrato * @param decimal $valorEmprestimo * @param int $qtdParcelas * @param decimal $jurosContrato * @return decimal */ public function price($valorEmprestimo, $qtdParcelas, $jurosContrato) { $juros = bcdiv($jurosContrato, 100, 15); $e = 1.0; $cont = 1.0; for ( $k = 1; $k <= $qtdParcelas; $k++ ) { $cont = bcmul($cont, bcadd($juros, 1, 15), 15); $e = bcadd($e, $cont, 15); } $e = bcsub($e, $cont, 15); $valor = bcmul($valorEmprestimo, $cont, 15); return bcdiv($valor, $e, 15); } public function calculaAvulso($dados){ $emprestimo = str_replace([ '.', ',' ], [ '', '.' ], $dados['valor_emprestimo']); $margem = str_replace([ '.', ',' ], [ '', '.' ], $dados['parcela']); $fator = str_replace([ '.', ',' ], [ '', '.' ], $dados['fator']); $saldoDevedor = str_replace([ '.', ',' ], [ '', '.' ], $dados['saldo_devedor']); if(!empty($fator)){ $emprestimo = !empty($dados['parcela']) ? ($margem / $fator) : $emprestimo; $parcela = (!empty($dados['valor_emprestimo']) && empty($dados['parcela'])) ? $emprestimo * $fator : $margem; $result = [ 'prazo' => $dados['prazo'], 'emprestimo' => !empty($saldoDevedor) ? $emprestimo - $saldoDevedor : $emprestimo, 'parcela' => $parcela ]; return $result; } return false; } public function calculaFatorNecessario($dados){ $margem = str_replace([ '.', ',' ], [ '', '.' ], $dados['parcela']); $saldoDevedor = str_replace([ '.', ',' ], [ '', '.' ], $dados['saldo_devedor']); if(!empty($margem)){ $fator = $margem / ( 100 + $saldoDevedor ); $result = [ 'fator' => $fator ]; return $result; } return false; } public static function getJurosContrato($vlEmprestimo, $vlParcela, $qtdParcelas, $nominal = false) { //FV=PV(1+i)^n $error = 0.0000001; $high = 1.00; $low = 0.00; $juros = (2.0 * ($qtdParcelas * $vlParcela - $vlEmprestimo)) / ($vlEmprestimo * $qtdParcelas); while(true) { // check for error margin $calc = pow(1 + $juros, $qtdParcelas); $calc = ($juros * $calc) / ($calc - 1.0); $calc -= $vlParcela / $vlEmprestimo; if ($calc > $error) { // guess too high, lower the guess $high = $juros; $juros = ($high + $low) / 2; } elseif ($calc < -$error) { // guess too low, higher the guess $low = $juros; $juros = ($high + $low) / 2; } else { // acceptable guess break; } } //se for nominal puxa até hoje if( $nominal ){ $juros = 0.008333; $qtdParcelas = 12; $txN = pow((1+$juros), $qtdParcelas)-1; pr($txN); } $percentual = $juros*100; return round($percentual, 4); } }
💾 保存文件
← 返回文件管理器