✏️ 正在编辑: DebitoCorretor.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DebitoCorretor.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DebitoCorretor 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'] = "DEBITO_CORRETOR"; return $data; } /** * Insere ou altera o registro passado por parâmetro * @param Model_DebitoCorretor $lancamento */ public function salvar(Model_DebitoCorretor $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('DEBITO_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 = 'DEBITO_CORRETOR' AND " . $where : "tipo = 'DEBITO_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 = 'DEBITO_CORRETOR'", 'excluido<>1' ); if (!empty($fields['categoria_id'])) { $params[] = "categoria_id = " . $fields['categoria_id']; } if (!empty($fields['corretor_id'])) { $params[] = "corretor_id = " . $fields['corretor_id']; } if (!empty($fields['descricao'])) { $params[] = "descricao LIKE '%" . $fields['descricao'] . "%'"; } if (!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['data_pagamento'])) { $params[] = "data_pagamento = STR_TO_DATE('" . $fields['data_pagamento'] . "', '%d/%m/%Y')"; } if (!empty($fields['data_pagamento_de'])) { $params[] = "data_pagamento >= STR_TO_DATE('" . $fields['data_pagamento_de'] . "', '%d/%m/%Y')"; } if (!empty($fields['data_pagamento_a'])) { $params[] = "data_pagamento <= STR_TO_DATE('" . $fields['data_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 = 'DEBITO_CORRETOR' AND DATE_FORMAT(data_pagamento, '%Y-%m') = '" . $data . "'"); $select->group(array( 'corretor_id', 'data_pagamento' )); return $dbtable->fetchAll($select); } }
💾 保存文件
← 返回文件管理器