✏️ 正在编辑: ProtocoloPagamentoIndicador.php
路径:
/srv/systems_dir/yuppiecred/application/models/ProtocoloPagamentoIndicador.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_ProtocoloPagamentoIndicador { private $_id; private $_dataBaixa; //datahora da baixa private $_dataPagamento; private $_comentario; private $_desconto; private $_acrescimo; private $_indicadorId; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getIndicadorId() { return $this->_indicadorId; } public function setIndicadorId($indicadorId) { $this->_indicadorId = $indicadorId; } public function getDataBaixa() { return $this->_dataBaixa; } public function setDataBaixa($dataBaixa) { $this->_dataBaixa = $dataBaixa; } public function getDataPagamento() { return $this->_dataPagamento; } public function setDataPagamento($dataPagamento) { if (!empty($dataPagamento)) { try { $data = new Zend_Date($dataPagamento, Zend_Date::DATES, 'pt'); $dataPagamento = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataPagamento = null; } } else { $dataPagamento = null; } $this->_dataPagamento = $dataPagamento; } public function getComentario() { return $this->_comentario; } public function setComentario($comentario) { $this->_comentario = $comentario; } public function getDesconto() { return $this->_desconto; } public function setDesconto($desconto) { $this->_desconto = str_replace(['.', ','], ['', '.'], $desconto); } public function getAcrescimo() { return $this->_acrescimo; } public function setAcrescimo($acrescimo) { $this->_acrescimo = str_replace(['.', ','], ['', '.'], $acrescimo); } 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_ProtocoloPagamentoIndicador(); $info = $dbtable->info(); $methods = get_class_methods($this); $data = []; 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; } /** * Insere ou altera o registro passado por parâmetro * @param Model_ProtocoloPagamentoIndicador $protocolo */ public function salvar(Model_ProtocoloPagamentoIndicador $protocolo) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); if ($protocolo->getId() > 0) { $dbtable->update($protocolo->_toArray(), "id = " . $protocolo->getId()); return $protocolo->getId(); } else { return $dbtable->insert($protocolo->_toArray()); } } /** * Exclui o registro passado por parâmetro * @param int $id * @return int The number of rows deleted */ public function excluir($id) { if( $id > 0 ){ $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); return $dbtable->excluirProtocolo($id); } return null; } /** * Retorna uma lista * @param string $where * @param string $order * @param int $count * @param int $offset * @return array */ public function listar($where = null, $order = null, $count = null, $offset = null) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); return $dbtable->fetchAll($where, $order, $count, $offset); } /** * Retorna um fetchRow do item passado por parâmetro * @param int $id * @return Zend_Db_Table_Row_Abstract | null */ public function exibir($id) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); return $dbtable->fetchRow("id = $id"); } public function listarProtocolos($fields = null) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); $selectContratos = $dbtable->getAdapter()->select() ->from(['contratos' => 'tb_contratos'], ['contratos.id', 'base_comissao_valor', 'comissao_corretor', 'comissao_empresa']) ->where('contratos.excluido <> 1') ->group('contratos.id'); $select = $dbtable->getAdapter()->select()->from(['protocolos' => 'tb_protocolo_pagamento_indicador']) ->joinInner(['protocolos_itens' => 'tb_protocolo_pagamento_indicador_itens'], 'protocolos.id = protocolos_itens.protocolo_id', ['vl_comissao' => 'SUM(protocolos_itens.valor_comissao)']) ->joinInner(['indicadores' => 'tb_corretores'], 'protocolos.indicador_id = indicadores.id', ['indicador' => 'nome', 'banco', 'agencia', 'conta', 'titular', 'cpf_titular', 'tipo_conta']) ->joinInner(['contratos' => $selectContratos], 'protocolos_itens.contrato_id = contratos.id', ['total_base_comissao' => 'SUM(contratos.base_comissao_valor)', 'comissao_corretor', 'comissao_empresa']) ->where('protocolos.excluido <> 1') ->group(['protocolos.id']); if (!empty($fields['data_pagamento_de']) && !empty($fields['data_pagamento_a'])) { $dataDe = new Zend_Date($fields['data_pagamento_de'], 'dd/MM/yyyy'); $dataA = new Zend_Date($fields['data_pagamento_a'], 'dd/MM/yyyy'); $select->where("protocolos.data_pagamento >= ?", $dataDe->get('yyyy-MM-dd')) ->where("protocolos.data_pagamento <= ?", $dataA->get('yyyy-MM-dd')); } if (!empty($fields['protocolo_id'])) { $select->where("protocolos.id = '{$fields['protocolo_id']}'"); } if( !empty($fields['indicador_id']) ){ $select->where("protocolos.indicador_id = {$fields['indicador_id']}"); } return $dbtable->getAdapter()->fetchAll($select); } public function getProtocoloPagamentoIndicador($protocoloId) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); $selectContratos = $dbtable->getAdapter()->select() ->from(['contratos' => 'tb_contratos'], ['contratos.id', 'valor_liquido']) ->where('contratos.excluido <> 1') ->group('contratos.id'); $select = $dbtable->getAdapter()->select() ->from(['protocolos' => 'tb_protocolo_pagamento_indicador']) ->joinInner(['protocolos_itens' => 'tb_protocolo_pagamento_indicador_itens'], 'protocolos.id = protocolos_itens.protocolo_id', ['valor_comissao_indicador' => 'protocolos_itens.valor_comissao']) ->joinInner(['contratos' => $selectContratos], 'protocolos_itens.contrato_id = contratos.id', ['total_liquido' => 'SUM(contratos.valor_liquido)']) ->joinInner(['indicadores' => 'tb_corretores'], 'protocolos.indicador_id = indicadores.id', ['valor_comissao' => '(indicadores.valor_comissao)', 'indicador' => 'nome', 'banco', 'agencia', 'conta', 'titular', 'cpf_titular', 'tipo_conta']) ->where('protocolos.excluido <> 1') ->where("protocolos.id = $protocoloId") ->group(array( 'protocolos.id' )); return $dbtable->getAdapter()->fetchAll($select); } public function listarProtocolosMesmoContrato($protocoloId, $contratoId = null) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicador(); $select = $dbtable->getAdapter()->select() ->from(['protocolos' => 'tb_protocolo_pagamento_indicador_itens'], ["*"]) ->where("contrato_id IN (SELECT contrato_id FROM tb_protocolo_pagamento_indicador_itens WHERE protocolo_id = $protocoloId AND excluido <> 1)") ->where("protocolo_id > $protocoloId") ->where("excluido <> 1"); if ($contratoId) { $select->where("contrato_id = $contratoId"); } return $dbtable->getAdapter()->fetchRow($select); } public function getContratos($protocoloId) { $dbtable = new Model_DbTable_Contrato(); return $dbtable->fetchAllDependents([ "protocolo_pagamento_indicador_id" => $protocoloId ], 'data_pagamento_indicador ASC'); } public function pagarComissaoIndicador($contratoId, $valorComissao, $protocoloId) { if ($contratoId > 0 && $protocoloId > 0) { $dbtable = new Model_DbTable_ProtocoloPagamentoIndicadorItem(); if ($dbtable->fetchRow("contrato_id = $contratoId AND protocolo_id = $protocoloId") ){ throw new Exception("Contrato($contratoId) já possui protocolo($protocoloId) gerado."); } return $dbtable->insert([ 'contrato_id' => $contratoId, 'protocolo_id' => $protocoloId, 'valor_comissao' => $valorComissao ]); } return null; } }
💾 保存文件
← 返回文件管理器