✏️ 正在编辑: CreditoCorretor.php
路径:
/srv/systems_dir/yuppiecred-bkp/application/models/CreditoCorretor.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_CreditoCorretor extends Model_Lancamento { public function getCorretorId() { return $this->_corretorId; } public function setCorretorId($corretorId) { $this->_corretorId = $corretorId; } public function _toArray() { $dbtable = new Model_DbTable_Lancamento(); $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(); } } $data['tipo'] = "CREDITO_CORRETOR"; return $data; } /** * Insere ou altera o registro passado por parâmetro * @param Model_Despesa $despesa */ public function salvar(Model_CreditoCorretor $lancamento) { $dbtable = new Model_DbTable_Lancamento(); if( $lancamento->getId() > 0 ){ $dbtable->update($lancamento->_toArray(), "id = " . $lancamento->getId()); return $lancamento->getId(); } else { if( $this->getNumeroParcelas() > 1 ){ //insere a primeira parcela $dbtable->insert($lancamento->_toArray()); //insere a repeticao $this->repetir($this->preparaRepeticao('CREDITO_CORRETOR')); } else { return $dbtable->insert($lancamento->_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_Lancamento(); 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) { $where = $where != null ? "tipo = 'CREDITO_CORRETOR' AND " . $where : "tipo = 'CREDITO_CORRETOR'"; $dbtable = new Model_DbTable_Lancamento(); 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_Lancamento(); return $dbtable->fetchRow(["id = ?" => $id]); } public function getPaginatorAdapter($fields, $order = null) { $params = array( "tipo = 'CREDITO_CORRETOR'", 'excluido<>1' ); if( isset($fields['categoria_id']) && !empty($fields['categoria_id']) ){ $params[] = "categoria_id = " . $fields['categoria_id']; } if( isset($fields['corretor_id']) && !empty($fields['corretor_id']) ){ $params[] = "corretor_id = " . $fields['corretor_id']; } if( isset($fields['descricao']) && !empty($fields['descricao']) ){ $params[] = "descricao LIKE '%" . $fields['descricao'] . "%'"; } if( isset($fields['apelido']) && !empty($fields['apelido']) ){ $dbtableCorretor = new Model_DbTable_Corretor(); $corretor = $dbtableCorretor->fetchRow("(apelido LIKE '" . $fields['apelido'] . "' OR nome LIKE '" . $fields['apelido'] . "')"); if( is_object($corretor) && $corretor->id > 0 ) $params[] = "corretor_id = " . $corretor->id; } if( !empty($fields['pagamento_de']) && !empty($fields['pagamento_a']) ){ $params[] = "(data_pagamento >= STR_TO_DATE('" . $fields['pagamento_de'] . "', '%d/%m/%Y')" . " AND data_pagamento <= STR_TO_DATE('" . $fields['pagamento_a'] . "', '%d/%m/%Y'))"; } $where = null; if( count($params) > 0 ){ $where = implode(" AND ", $params); } $dbtable = new Model_DbTable_Lancamento(); $select = $dbtable->select(); if( $where != null ) $select->where($where); if( $order != null ) $select->order($order); return new Zend_Paginator_Adapter_DbTableSelect($select); } /** * * @param string $data * @return Zend_Db_Table_Rowset_Abstract | array | null */ public function getLancamentosDia($data) { return $this->listar("data_pagamento = '" . $data . "'", 'data_pagamento ASC'); } /** * * @param string $data YYYY-MM * @return Zend_Db_Table_Rowset_Abstract | array | null */ public function getLancamentosMes($data) { $dbtable = new Model_DbTable_Lancamento(); $select = $dbtable->select()->from('tb_lancamentos', array( 'valor_total' => "SUM(valor_pago)", 'corretor_id', 'data_pagamento' )); $select->where("excluido<>1 AND tipo = 'CREDITO_CORRETOR' AND DATE_FORMAT(data_pagamento, '%Y-%m') = '" . $data . "'"); $select->group(array( 'corretor_id', 'data_pagamento' )); return $dbtable->fetchAll($select); } /** * Retorna os créditos do período * @param type $dataInicial * @param type $dataFinal */ // public function getLancamentosPeriodo($dataInicial, $dataFinal) // { // $where = null; // // if( $dataInicial != null && $dataFinal != null ){ // $where = "data_pagamento >= STR_TO_DATE('" . $dataInicial . "', '%d/%m/%Y')" // . " AND data_pagamento <= STR_TO_DATE('" . $dataFinal . "', '%d/%m/%Y')"; // } // // return $this->listar($where, "data_pagamento ASC"); // // } }
💾 保存文件
← 返回文件管理器