✏️ 正在编辑: Rota.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/Rota.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_Rota { private $_id; private $_nome; private $_gerenteId; private $_valorHospedagem; private $_valorRefeicao; private $_valorCombustivel; private $_consumoVeiculo; private $_termoId; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getNome() { return $this->_nome; } public function setNome($nome) { $this->_nome = $nome; } public function getGerenteId() { return $this->_gerenteId; } public function setGerenteId($gerenteId) { $this->_gerenteId = $gerenteId; } public function getValorHospedagem() { return $this->_valorHospedagem; } public function getValorRefeicao() { return $this->_valorRefeicao; } public function getValorCombustivel() { return $this->_valorCombustivel; } public function getConsumoVeiculo() { return $this->_consumoVeiculo; } public function getTermoId() { return $this->_termoId; } public function setTermoId($termoId) { $this->_termoId = $termoId; } public function setValorHospedagem($valorHospedagem) { if( Zend_Locale_Format::isFloat($valorHospedagem, array( 'precision' => 2 )) ){ $valorHospedagem = Zend_Locale_Format::getFloat($valorHospedagem, array( 'precision' => 2 )); } $this->_valorHospedagem = $valorHospedagem; return $this; } public function setValorRefeicao($valorRefeicao) { if( Zend_Locale_Format::isFloat($valorRefeicao, array( 'precision' => 2 )) ){ $valorRefeicao = Zend_Locale_Format::getFloat($valorRefeicao, array( 'precision' => 2 )); } $this->_valorRefeicao = $valorRefeicao; return $this; } public function setValorCombustivel($valorCombustivel) { if( Zend_Locale_Format::isFloat($valorCombustivel, array( 'precision' => 2 )) ){ $valorCombustivel = Zend_Locale_Format::getFloat($valorCombustivel, array( 'precision' => 2 )); } $this->_valorCombustivel = $valorCombustivel; return $this; } public function setConsumoVeiculo($consumoVeiculo) { if( Zend_Locale_Format::isFloat($consumoVeiculo, array( 'precision' => 2 )) ){ $consumoVeiculo = Zend_Locale_Format::getFloat($consumoVeiculo, array( 'precision' => 2 )); } $this->_consumoVeiculo = $consumoVeiculo; return $this; } 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_Rota(); $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; } /** * Insere ou altera o registro passado por parâmetro * @param Model_Rota $rota */ public function salvar(Model_Rota $rota) { $dbtable = new Model_DbTable_Rota(); if( $rota->getId() > 0 ){ $dbtable->update($rota->_toArray(), "id = " . $rota->getId()); return $rota->getId(); } else { return $dbtable->insert($rota->_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_Rota(); return $dbtable->delete("id = " . $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_Rota(); 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_Rota(); return $dbtable->fetchRow("id = " . $id); } public function getProducao($fields = null, $order = null, $group = null) { $params = array( "contratos.excluido<>1 AND tipo_registro = 1" ); if( Yuppie_Auth::getIdentity()->grupo == "Supervisor" ){ $params[] = "rotas.gerente_id = " . Yuppie_Auth::getIdentity()->id; } elseif( Yuppie_Auth::getIdentity()->grupo == "Gerente Regional" ){ $params[] = "gerentes.id = " . Yuppie_Auth::getIdentity()->id; } $dbtable = new Model_DbTable_Rota(); $selectProtocoloPagamento = $dbtable->getAdapter()->select()->from('tb_protocolo_pagamento', array( 'data_pagamento', 'id' )) ->joinInner(array( 'tb_protocolo_contrato' ), 'tb_protocolo_pagamento.id = tb_protocolo_contrato.protocolo_id', array( 'contrato_id' )) ->where('tb_protocolo_pagamento.excluido<>1 AND tb_protocolo_contrato.excluido<>1'); $select = $dbtable->getAdapter()->select()->from(array( 'contratos' => "tb_contratos" ), array( 'data_liberacao', 'quantidade_total' => 'COUNT(contratos.id)', 'total_producao' => 'SUM(valor_liquido)', 'mes_producao' => "DATE_FORMAT(data_liberacao, '%Y-%m')" )) ->joinLeft(array( 'corretores' => "tb_corretores" ), 'contratos.corretor_id = corretores.id', array()) ->joinLeft(array( 'rotas' => "tb_rotas" ), 'corretores.rota_id = rotas.id', array( 'rota' => 'nome' )) ->joinLeft(array( 'gerentes_rotas' => "tb_gerente_rota" ), 'rotas.gerente_id = gerentes_rotas.id', array()) ->joinLeft(array( 'gerentes' => "tb_gerentes" ), 'gerentes_rotas.gerente_id = gerentes.id', array()) ->joinLeft(array( 'status_propostas' => "tb_tipos" ), "contratos.status_proposta = status_propostas.id", array( 'status_proposta_nome' => 'descricao' )) ->joinLeft(array( 'protocolos_pagamentos' => $selectProtocoloPagamento ), "protocolos_pagamentos.contrato_id = contratos.id", array( 'protocolo_pagamento_gerado' => 'MAX(protocolos_pagamentos.id)' )); //trata os filtros if( isset($fields['data_pagamento_de']) && !empty($fields['data_pagamento_de']) && isset($fields['data_pagamento_a']) && !empty($fields['data_pagamento_a']) ){ $params[] = "(protocolos_pagamentos.data_pagamento >= STR_TO_DATE('" . $fields['data_pagamento_de'] . "', '%d/%m/%Y') AND " . " protocolos_pagamentos.data_pagamento <= STR_TO_DATE('" . $fields['data_pagamento_a'] . "', '%d/%m/%Y'))"; } if( isset($fields['data_emissao_de']) && !empty($fields['data_emissao_de']) && isset($fields['data_emissao_a']) && !empty($fields['data_emissao_a']) ){ $params[] = "(data_emissao >= STR_TO_DATE('" . $fields['data_emissao_de'] . "', '%d/%m/%Y')" . " AND data_emissao <= STR_TO_DATE('" . $fields['data_emissao_a'] . "', '%d/%m/%Y'))"; } if( isset($fields['data_liberacao_de']) && !empty($fields['data_liberacao_de']) && isset($fields['data_liberacao_a']) && !empty($fields['data_liberacao_a']) ){ $params[] = "(data_liberacao >= STR_TO_DATE('" . $fields['data_liberacao_de'] . "', '%d/%m/%Y')" . " AND data_liberacao <= STR_TO_DATE('" . $fields['data_liberacao_a'] . "', '%d/%m/%Y'))"; } if( isset($fields['rota_id']) && !empty($fields['rota_id']) ){ $params[] = "rotas.id = " . $fields['rota_id']; } if( isset($fields['gerente_id']) && !empty($fields['gerente_id']) ){ $params[] = "gerentes.id = " . $fields['gerente_id']; } if( isset($fields['supervisor_id']) && !empty($fields['supervisor_id']) ){ $params[] = "gerentes_rotas.id = " . $fields['supervisor_id']; } $where = null; if( count($params) > 0 ) $where = implode(" AND ", $params); if( $where != null ) $select->where($where); if( $order != null ){ $select->order($order); } if( $group != null ){ $select->group($group); } return $dbtable->getAdapter()->fetchAll($select); } public function getTotalProducao($fields = null, $order = null, $group = null) { $params = array( "contratos.excluido<>1 AND tipo_registro = 1" ); if( Yuppie_Auth::getIdentity()->grupo == "Supervisor" ){ $params[] = "rotas.gerente_id = " . Yuppie_Auth::getIdentity()->id; } elseif( Yuppie_Auth::getIdentity()->grupo == "Gerente Regional" ){ $params[] = "gerentes.id = " . Yuppie_Auth::getIdentity()->id; } $dbtable = new Model_DbTable_Rota(); $select = $dbtable->getAdapter()->select()->from(array( 'contratos' => "tb_contratos" ), array( 'total_producao' => 'SUM(valor_liquido)' )) ->joinLeft(array( 'corretores' => "tb_corretores" ), 'contratos.corretor_id = corretores.id', array()) ->joinLeft(array( 'rotas' => "tb_rotas" ), 'corretores.rota_id = rotas.id', array( 'rota' => 'nome' )) ->joinLeft(array( 'gerentes_rotas' => "tb_gerente_rota" ), 'rotas.gerente_id = gerentes_rotas.id', array()) ->joinLeft(array( 'gerentes' => "tb_gerentes" ), 'gerentes_rotas.gerente_id = gerentes.id', array()) ->joinLeft(array( 'protocolos_pagamentos' => "tb_protocolo_pagamento" ), "contratos.protocolo_pagamento_id = protocolos_pagamentos.id", array()); //trata os filtros if( isset($fields['data_pagamento_de']) && !empty($fields['data_pagamento_de']) && isset($fields['data_pagamento_a']) && !empty($fields['data_pagamento_a']) ){ $params[] = "(protocolos_pagamentos.data_pagamento >= STR_TO_DATE('" . $fields['data_pagamento_de'] . "', '%d/%m/%Y') AND " . " protocolos_pagamentos.data_pagamento <= STR_TO_DATE('" . $fields['data_pagamento_a'] . "', '%d/%m/%Y'))"; } if( isset($fields['rota_id']) && !empty($fields['rota_id']) ){ $params[] = "rotas.id = " . $fields['rota_id']; } if( isset($fields['gerente_id']) && !empty($fields['gerente_id']) ){ $params[] = "gerentes.id = " . $fields['gerente_id']; } if( isset($fields['supervisor_id']) && !empty($fields['supervisor_id']) ){ $params[] = "gerentes_rotas.id = " . $fields['supervisor_id']; } $where = null; if( count($params) > 0 ) $where = implode(" AND ", $params); if( $where != null ) $select->where($where); if( $order != null ){ $select->order($order); } if( $group != null ){ $select->group($group); } $value = $dbtable->getAdapter()->fetchRow($select); if( $value != null ) return $value['total_producao']; return 0; } public function getRotasIdBySupervisor($supervisorId) { if( $supervisorId > 0 ){ $dbtable = new Model_DbTable_Rota(); $select = $dbtable->getAdapter()->select()->from('tb_rotas', array( 'id' )) ->where("gerente_id = {$supervisorId}"); $rotas = $dbtable->getAdapter()->fetchCol($select); return $rotas; } return null; } public function getTotalValores($id) { if( $id > 0 ){ $dbtable = new Model_DbTable_Rota(); $select = $dbtable->getAdapter()->select()->from('tb_rotas', array( 'id','total_valores' => '(SUM(valor_hospedagem)+SUM(valor_refeicao)+SUM(valor_combustivel))' )) ->where("tb_rotas.id = {$id}"); $total = $dbtable->getAdapter()->fetchRow($select); return $total; } return null; } public function atualizarRotas($params) { $dbtable = new Model_DbTable_Rota(); $count = 0; $vlr = String_Refatorar::parseStringToFloat($params['vlr_atualizar']); foreach ($params['rotas'] as $rota) { try { $id = $dbtable->update([$params['campo'] => $vlr], 'id = ' . $rota); $count += $id ? 1 : 0; } catch ( Zend_Exception $e ) { Yuppie_Log::write("Falha na atualização da rota " . $rota . '. Erro: ' . $e->getMessage(), $this); } } return $count; } }
💾 保存文件
← 返回文件管理器