<?php

class Sinistro2_Model_CobrancaRelatorioLogAlteracaoNotas extends Agro_Db_Table_Abstract {
	protected $_rowClass = 'Sinistro2_Model_Row_CobrancaRelatorioLogAlteracaoNotas';
	protected $_schema = 'sinistro';
	protected $_name = 'cobranca_relatorio_log_alteracao_notas';
	protected $_primary = 'id';
	
	public function save($values){
		try {
			$Row = $this->createRow();
			
			$Row->id_cobranca_relatorio = $values["id_cobranca_relatorio"];
			$Row->nr_nota_antiga = $values["nr_nota_antiga"];
			$Row->nr_nota_nova = $values["nr_nota_nova"];
			
			return $Row->save();
			
		} catch (Exception $e) {
			$this->setMessage($e->getMessage());
			return false;
		}
	}

	public function findUltimoLogAlteracaoNotaByIdCobrancaRelatorio(int $idCobrancaRelatorio) {
		return $this->_db->fetchRow(
			$this->select()
				->setIntegrityCheck(false)
				->where('id_cobranca_relatorio = ?', $idCobrancaRelatorio)
				->order('dt_criacao DESC')
				->limit(1)
		);
	}
}
