✏️ 正在编辑: Tributo.php
路径:
/srv/systems_dir/yuppiecred/application/models/Tributo.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_Tributo { private $_id; private $_tipo; private $_valorInicial; private $_valorFinal; private $_percentual; private $_valorDeducao; private $_valorDependenteIrpf; public function __construct($options = null) { if( is_array($options) ){ $this->setOptions($options); } } public function setOptions(array $options) { $methods = get_class_methods($this); foreach ( $options as $key => $value ) { $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'set' . ucfirst($key); if( in_array($method, $methods) ){ $this->$method($value); } } return $this; } public function _toArray() { $dbtable = new Model_DbTable_Tributo(); $info = $dbtable->info(); $methods = get_class_methods($this); $data = array(); foreach ( $info['cols'] as $key ) { $col = $key; $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'get' . ucfirst($key); if( in_array($method, $methods) ){ $data[$col] = $this->$method(); } } return $data; } public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; return $this; } public function getTipo() { return $this->_tipo; } public function getValorInicial() { return $this->_valorInicial; } public function getValorFinal() { return $this->_valorFinal; } public function getPercentual() { return $this->_percentual; } public function setTipo($tipo) { $this->_tipo = $tipo; return $this; } public function setValorInicial($valorInicial) { $this->_valorInicial = str_replace(array( '.', ',' ), array( '', '.' ), $valorInicial); return $this; } public function setValorFinal($valorFinal) { $this->_valorFinal = str_replace(array( '.', ',' ), array( '', '.' ), $valorFinal); return $this; } public function setPercentual($percentual) { $this->_percentual = str_replace(array( '.', ',' ), array( '', '.' ), $percentual); return $this; } public function getValorDeducao() { return $this->_valorDeducao; } public function setValorDeducao($valorDeducao) { $this->_valorDeducao = str_replace(array( '.', ',' ), array( '', '.' ), $valorDeducao); return $this; } public function getValorDependenteIrpf() { return $this->_valorDependenteIrpf; } public function setValorDependenteIrpf($valorDependenteIrpf) { $this->_valorDependenteIrpf = str_replace(array( '.', ',' ), array( '', '.' ), $valorDependenteIrpf); return $this; } public function listar($fields = null, $order = null) { $params = array( 'tributos.excluido<>1' ); $params = array( 'tributos.tipo<>"DEPENDENTE"' ); if( isset($fields['tipo']) && !empty($fields['tipo']) ){ $params[] = "tributos.tipo LIKE '%" . $fields['tipo'] . "%'"; } $dbtable = new Model_DbTable_Tributo(); $select = $dbtable->getAdapter()->select()->from(array( 'tributos' => 'tb_tributos' ), array( 'tributos.*' )); if( $order != null ){ $select->order($order); } $select->where(implode(" AND ", $params)); return $dbtable->getAdapter()->fetchAll($select); } public static function valorDependente() { $dbtable = new Model_DbTable_Tributo(); $dados = array( 'valor_dependente_irpf' => 0, 'id' => 0 ); $valor = $dbtable->fetchRow("tipo = 'DEPENDENTE'"); if( $valor == null ){ $dados = array( 'valor_dependente_irpf' => 0, 'id' => 0 ); } else { $dados = array( 'valor_dependente_irpf' => $valor->valor_dependente_irpf, 'id' => $valor->id, ); } return $dados; } public function exibir($id) { $dbtable = new Model_DbTable_Tributo(); return $dbtable->fetchRow("id = " . $id); } public function salvar(Model_Tributo $tributo) { $dbtable = new Model_DbTable_Tributo(); if( $tributo->getId() > 0 ){ $dbtable->update($tributo->_toArray(), "id = " . $tributo->getId()); return $tributo->getId(); } else { return $dbtable->insert($tributo->_toArray()); } } public static function calculoDescontoInss($salario) { $dbtable = new Model_DbTable_Tributo(); $base = array( 'base' => 0.00, 'percentual' => 0.00, ); $select = $dbtable->select()->from('tb_tributos', array( 'valor_minimo' => "MIN(valor_inicial)", "percentual_minimo" => "MIN(percentual)", 'valor_maximo' => "MAX(valor_final)", "percentual_maximo" => "MAX(percentual)" )) ->where("tipo LIKE 'INSS'"); $dados = $dbtable->getAdapter()->fetchRow($select); if( $salario > $dados['valor_maximo'] ){ $base = array( 'base' => $dados['valor_maximo'], 'percentual' => $dados['percentual_maximo'], ); } elseif( $salario < $dados['valor_minimo'] ){ $base = array( 'base' => $salario, 'percentual' => $dados['percentual_minimo'], ); } else { $where = "tipo = 'INSS' AND (valor_final >= " . $salario . ") AND (valor_inicial <= " . $salario . ")"; $dados = $dbtable->fetchRow($where); if( $dados != null ){ $base = array( 'base' => $salario, 'percentual' => $dados['percentual'], ); } } return ($base['base'] * $base['percentual']) / 100; } public static function calculoDescontoIrpf($salario) { $dbtable = new Model_DbTable_Tributo(); $base = array( 'base' => 0.00, 'percentual' => 0.00, ); $where = "tipo = 'IRPF' AND (valor_final >= " . $salario . ") AND (valor_inicial <= " . $salario . ")"; $dados = $dbtable->fetchRow($where); if( $dados == null ){ $base = array( 'deducao' => 0.00, 'percentual' => 0.00, ); } else { $base = array( 'deducao' => $dados['valor_deducao'], 'percentual' => $dados['percentual'], ); } return ($salario * $base['percentual'] / 100) - $base['deducao']; } }
💾 保存文件
← 返回文件管理器