<?php

$User = Zend_Auth::getInstance()->getIdentity();
if($User->tp_usuario == 'F') {
	$this->adminView = true;
} else {
	$this->adminView = false;
}

$this->title = 'Sinistro » Avisos » Visualizar';
$this->showPrint = true;
$this->date = new Zend_Date();
$this->dateFormat = 'dd/MM/Y';

$ModelVistoriaPrevia  = new Seguro_Model_VistoriaPreviaEmpresa();
$Safra                = new Produto_Model_Safras();
$ModelProposta        = new Sinistro2_Model_Propostas();
$ModelPropostaSeguro  = new Seguro_Model_Propostas();
$ModelAtendimento     = new Atendimento_Model_Proposta();
$ModelAviso           = new Sinistro2_Model_AvisosSinistro();

$aviso       = $ModelAviso->fetchRow($ModelAviso->getAdapter()->quoteInto('id = ?',$this->id_aviso));
$this->data  = $ModelAviso->loadAvisoSinistro($this->id_aviso);
$this->aviso = $aviso;

$this->proposta = $ModelProposta->find($this->id_proposta)->current();
$produto = $this->proposta->produto();
$proponente = $this->proposta->proponente();
$propriedade = $this->proposta->propriedade();
$atributos = $this->proposta->atributos_rn('UNIDADE_SEGURADA');
$beneficiarios = $this->proposta->beneficiarios();
$coberturasAdicionais = $this->proposta->coberturas_contratadas('adicional');
$coberturaPrincipal = $this->proposta->coberturas_contratadas('principal');
$corretor = $this->proposta->corretor();
$observacoes = $this->proposta->observacoes();
$carencia = $this->proposta->carencia();
$croquis = $this->proposta->croquis();
$producaoGarantida = $this->proposta->atributos('PROPRIEDADE', 'PROD_PRODUCAO_GARANTIDA');
$pessoa_autorizada = $this->proposta->pessoa_autorizada();

$id_proposta_exibicao = ($this->proposta->versao_endosso(false) > 0) ? $this->proposta->id_proposta_mae($this->proposta->id) : $this->proposta->id;

//Verifica se os Itens Segurados devem ser ocultados em virtude de endosso
$ocultarItensSegurados = $this->proposta->ocultarItensSegurados();
if($ocultarItensSegurados){
	$this->informacoesAdicionais = $ModelAtendimento->getObservacoesProposta($this->proposta->id);
}else{
	$this->informacoesAdicionais = $ModelAtendimento->getInfoAdicionais($this->proposta->id);
}

//Verifica se foi realizada vistoria previa
$this->ds_empresa_previa = $ModelAviso->getEmpresaPrevia($this->proposta->id);
if($this->data['id_proposta_vistoria'] > 0){
	$previas = $ModelVistoriaPrevia->countLaudos($this->proposta->id);
}

//Identifica se já existe um processo relacionado à proposta do aviso
$ModelProcesso = new Sinistro2_Model_Processos();
$processo = $ModelProcesso->fetchRow('id_proposta = '.$this->proposta->id);
if($processo){
	$processo = $processo->toArray();
	$this->form->id_processo->setValue($processo['id']);

	// Definindo valor default para combo de empresas
	$processoEmpresa = $ModelProcesso->getEmpresaVistoriadora($processo['id']);
	if($processoEmpresa){
		$this->idEmpresaProcesso = $processoEmpresa['id'];
		$this->form->empresas->setValue($processoEmpresa['id']);
	}
	$this->data['dsNomeEmpresaVistoriadora'] = $processoEmpresa['ds_nome_fantasia'];
	$this->data['id_processo'] = $processo['id'];
} else {
	/*
	 * Verifica se já existe Processo de Sinistro para alguma outra proposta do segurado e em caso
	* positivo sugere que o novo processo seja encaminhado para a mesma empresa do existente
	*/
	$Empresa = $ModelAviso->getVistoriadoraByCpfCnpjSeguradoSafra($proponente['cpf_cnpj'], $produto['id_safra']);
	if($Empresa) {
		$this->idEmpresaProcesso = $Empresa->id;
		$this->form->empresas->setValue($Empresa->id);
		$this->vistoriadoraByCpfCnpjNome = $Empresa->ds_nome_fantasia;
	}
	$this->form->id_processo->setValue(null);
}

if($this->data['ds_chave_status'] == 'PENDENTE') {
	list($dtAviso) = explode(' ', $this->data['dt_sinistro']);
	$this->data['arAvisosExistentes'] = $ModelAviso->getAvisosByPropostaDataAviso($this->proposta->id, $this->id_aviso, $dtAviso);
}

$PropostaCobertura = new Seguro_Model_PropostasCoberturas();
$this->listChaveCoberturas = $PropostaCobertura->getChaveCoberturasByProposta($this->proposta->id);

foreach($this->data['eventos'] as $it):
	$eventos .= $it['ds_nome_evento'] . ', ';
	$id_eventos[] = $it['id_evento'];
endforeach;

foreach ($coberturasAdicionais as $cobertura):
	$id_coberturas[] = $cobertura['id'];
endforeach;

$PropostaSeguro = $ModelPropostaSeguro->find($this->proposta->id)->current();

//Pega o arquivo (planilha) do laudo de preenchimento
$ModelLaudosPerito = new Sinistro2_Model_LaudosPerito();
$sqlLaudosPerito = $ModelLaudosPerito->select()->distinct(true)->setIntegrityCheck(false);
$sqlLaudosPerito->from(array("l"=>"sinistro.v_produto_cobertura_por_laudo"), array("id_laudo"));
$sqlLaudosPerito->join("produto.coberturas_eventos", "l.id_cobertura = coberturas_eventos.id_cobertura", array());
$sqlLaudosPerito->where("l.id_safra = {$produto['id_safra']}");
$sqlLaudosPerito->where("l.id_produto = {$produto['id']}");
$sqlLaudosPerito->where("coberturas_eventos.id_evento in (".(count($id_eventos) > 1 ? implode(',',$id_eventos) : $id_eventos[0]).")");
$sqlLaudosPerito->where("l.id_cobertura in (".$coberturaPrincipal['id'].(count($id_coberturas) > 0 ? ",".implode(',',$id_coberturas) : "").")");
$sqlLaudosPerito->where("l.fl_ativo = 't'");
//$sqlLaudosPerito->where("l.id_cobertura = {$coberturaPrincipal['id']}");
//dump($sqlLaudosPerito);
$RowLaudos = $ModelLaudosPerito->fetchAll($sqlLaudosPerito)->toArray();

$linkLF = "";
$linkLP = "";
//dump($RowLaudos);
foreach ($RowLaudos as $id_laudos){
	$arquivoLaudo = $ModelLaudosPerito->fetchAll("id = ".$id_laudos['id_laudo']." AND id_safra = ".$produto['id_safra']." AND fl_ativo = 't'");
 	if ($arquivoLaudo['tipo']->tipo == 'Laudo Final') {
		$linkLF .= $arquivoLaudo['chave']->chave."<a title='Clique aqui para fazer o download do arquivo' href='/agronet/file/view/path/planilhas_laudos_finais/name/".$arquivoLaudo['arquivo']->arquivo."' target='_blank'>
				  <img src='/resources/imagens/mini/download.png' border='0'></a>";
	} elseif ($arquivoLaudo['tipo']->tipo == 'Laudo Preliminar') {
		$linkLP .= $arquivoLaudo['chave']->chave."<a title='Clique aqui para fazer o download do arquivo' href='/agronet/file/view/path/planilhas_laudos_preliminares/name/".$arquivoLaudo['arquivo']->arquivo."' target='_blank'>
				  <img src='/resources/imagens/mini/download.png' border='0'></a>";
	}
}

?>
<link rel="stylesheet" href="/resources/css/seguro/proposta.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/resources/css/print.css" type="text/css" media="print" />
<link rel="stylesheet" href="/resources/css/seguro/propostaview.css" type="text/css" media="screen" />

<div class="proposta">

 	<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
		<tr>
			<td colspan="2">
				<table width="100%" border="0">
					<tr>
						<td width="100" style="border: 0px">
							<img src="/resources/imagens/essor.png" width="139" height="60">
						</td>
						<td style="border: 0px; padding-top: 30px">
							<center style="font-size: 18px; font-weight: bold;">Aviso de Sinistro Nro: <?=$this->data['id_aviso']?></center>
						</td>
					</tr>
				</table>
			</td>
		<tr>
		<tr align="center" border="0" style="font-weight: bold;">
			<td width="50%" style="vertical-align: middle">
				PROPOSTA NRO: <?=($PropostaSeguro->possuiEndosso(true) ? "<img src='/resources/imagens/mini/active.png' alt='active.png' title='Possui Endosso' border='0'>" : "")?>&nbsp;
				<?=$id_proposta_exibicao?>&nbsp;<?=($User->tp_usuario == 'F' ? "<a href='/seguro/proposta/view/id/".$this->proposta->id."' class='popup'><img src='/resources/imagens/mini/view.png' alt='view.png' title='Visualizar' border='0'></a>": "")?>
			</td>
			<td style="vertical-align: middle">
				<? if($this->data['id_processo']): ?>
					PROCESSO DE SINISTRO NRO: <?=$this->data['id_processo']?>
				<? endif; ?>
			</td>
		</tr>

		<? if($this->data['ds_motivo_recusa']): ?>
        <tr bgcolor="#f7aa0f">
			<td colspan="4">
					<b>Aviso Recusado. Motivo:</b><br><?=$this->data['ds_motivo_recusa']?>
			</td>
		</tr>
		<? endif; ?>

	</table>

	<input type="hidden" name="id_aviso" id="id_aviso" value="<?=$this->id_aviso?>"/>

	<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
		<tr>
			<td colspan="2"><b>PRODUTO:</b>&nbsp;<?=$produto['ds_nome_produto']?>&nbsp;®</td>
			<td colspan="2"><b>Safra:</b> <?=$produto['ds_nome_safra']?></td>
		</tr>
		<tr>
			<td colspan="2" style="vertical-align: middle"><b>Cobertura Principal:</b>&nbsp;<?=($produto['id'] == 734) ? 'Multirisco II' : $coberturaPrincipal['ds_nome_cobertura']?></td>
			<? if($User->tp_usuario != 'C' && Zend_Auth::getInstance()->getIdentity()->ds_chave != 'SEGURADORA_ESSOR' && Zend_Auth::getInstance()->getIdentity()->ds_chave != 'SEGURADORA'): ?>
				<td width="28%" style="vertical-align: middle"><b>L. Preliminar</b>&nbsp;<?=($linkLP ? $linkLP : "")?></td>
				<td width="23%" style="vertical-align: middle"><b>L. Final</b>&nbsp;<?=($linkLF ? $linkLF : "")?></td>
			<? else: ?>
				<td colspan="2">&nbsp;</td>
			<? endif; ?>
		</tr>
		<tr>
			<? $dataHoraSinistro = explode(' ',$this->data['dt_sinistro']);?>
			<td width="42%"><b>Evento:</b>&nbsp;<?=substr($eventos,0,-2)?></td>
			<td><b>Data/Hora Sinistro:</b>&nbsp;<?=Agro_Util::formatDate($dataHoraSinistro[0], Zend_Date::DATES)?>&nbsp;<? $hora = explode(':',$dataHoraSinistro[1]); echo $hora[0] . ':' . $hora[1]?></td>
			<td colspan="2" width="30%"><b>Data Envio Aviso:</b>&nbsp;<?=Agro_Util::formatDate($this->data['dt_criacao'], Zend_Date::DATES);?></td>
		</tr>

		<?
			if ($coberturasAdicionais):
				foreach ($coberturasAdicionais as $cobertura):
					$stCobertura .= $cobertura['ds_nome_cobertura'].', ';
				endforeach;
				?>
					<tr>
						<td colspan="2"><b>Coberturas adicionais:</b> <?=substr($stCobertura,0,-2)?></td>
						<td colspan="2"><b>Aviso de:</b> (<?=($this->data['fl_ocorrencia_replantio'] ? "X" : "&nbsp;")?>) replantio (<?=($this->data['fl_ocorrencia_queda_parreiral'] ? "X" : "&nbsp;")?>) queda</td>
					</tr>
				<?
			endif;
		?>
        <tr>
            <td colspan="4" height="30px"><b>Observação:</b><br><?=$this->aviso->ds_observacoes?></td>
        </tr>


	</table>

	<? if(($previas) && ($User->tp_usuario != 'C')): ?>
    	<table width="100%" cellpadding="0" cellspacing="0" class="gadget">
   		<tr>
   			<td style="border-bottom: 0px; border-right: 0px" width="50%">
   				<b>Vistoria Prévia:</b>&nbsp; <?=$this->ds_empresa_previa ? "Realizada por <b>&nbsp;".$this->ds_empresa_previa."</b>" : ""?>
   			</td>
   			<td style="align: right; border-left: 0px; border-bottom: 0px; border-right: 0px">
   				(Na ausência de endosso considerar a prévia na hora de fazer a vistoria de sinistro)
   			</td>
   			<td style="align: right; border-bottom: 0px; border-left: 0px">
   				<?
                   	$Endossos = $this->proposta->buscaPropostasEndosso();
                    foreach($Endossos as $proposta){
	                    $ponteiro  = opendir(PATH_LAUDOS);

	                    // monta os vetores com os itens encontrados na pasta
                    	while ($laudo = readdir($ponteiro)){
                    		if(substr($laudo,0,6) == $proposta){
                    			$tipo_laudo = substr($laudo,7,2);
                    	    	switch($tipo_laudo){
                    		        case "VP": $VP[] = $laudo; break;
                    		    }
                    		}
                    	}
                            closedir($ponteiro);
                    }

        	        if(is_array($VP)){
        	        	foreach($VP as $chave => $valor){
        	            ?>
    						<a href="/laudos/<?=$valor; ?>" target="_blank"><strong><?=$valor;?></strong></a>&nbsp;
        	            <?
        	            }
        	        }/** else {
        	                echo "SOLICITAR O LAUDO DE PRÉVIA À AGROBRASIL.";
        	        }**/
                ?>
			</td>
    	</tr>
		<tr>
			<td colspan="3"  style="border-top: 0px">
			<?
			// Busca informacões sobre Vistoria Previa
			$VistoriaPrevia = new Seguro_Model_VistoriaPreviaEmpresa();
			$arInfoVistoriaPrevia = $VistoriaPrevia->getStatusAnaliseByProposta($this->proposta->id);

			$ModelSafras = new Produto_Model_Safras();
			$model = $ModelSafras->getSafraModel($this->proposta->id, "Lvp001");
			$ModelLvp001 = new $model();

			foreach($arInfoVistoriaPrevia as $key => $vistoria){
				$arLaudo = $ModelLvp001->getLaudo($vistoria['id_proposta_vistoria']);
				if($arLaudo['id'] > 0){
					?>
					<a style="color: blue" href="/scripts/kmlprevia/proposta/<?=$this->proposta->id?>/id_laudo/<?=$arLaudo['id']?>"><b>Baixar Coordenadas Geográficas do Laudo - <?=$arLaudo['id']?></b></a><br>
					<?
				}
			}
			?>
			</td>
		</tr>
	</table>
	<? endif;

	if ($ocultarItensSegurados == true) {
	    unset($exibeInfo);
	    foreach($this->informacoesAdicionais as $infoAdicional){
	        if($infoAdicional['fl_observacao_endosso'] == true) {
	            $exibeInfo = true;
	        }
	    }
	    ?>

		<? if(($exibeInfo) & ($User->tp_usuario != 'C')) : ?>
			<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
			<thead>
				<tr>
	            	<th width="100%" align="center" colspan="4">Informações Adicionais da Proposta</th>
	            </tr>
	        </thead>
	            <tr>
	                <td><strong>Observação</strong></td>
	                <?=($User->tp_usuario == 'F' ? "<td><strong>Usuário</strong></td>" : "" )?>
	                <td><strong>Data</strong></td>
	                <td><strong>Arquivo</strong></td>
	            </tr>
	            <?
	            foreach($this->informacoesAdicionais as $infoAdicional){
	                if($infoAdicional['fl_observacao_endosso'] == true) { ?>
				        <tr bgcolor="#f7aa0f">
			 			     <td><?=$infoAdicional['ds_observacao']; ?></td>
				             <?=($User->tp_usuario == 'F' ? "<td>".$infoAdicional['ds_nome_usuario']."</td>" : "" )?>
				             <td><?=Agro_Util::formatDate($infoAdicional['dt_criacao'],Zend_Date::DATES); ?></td>
							 <td>
								 <? if($infoAdicional['ds_nome_arquivo']){?>
								     <a href="/agronet/file/propostasobservacoesarquivos/id/<?=$infoAdicional['id_observacao_arquivo']?>" target="blank"><img border="0" src="/resources/imagens/mini/download.png"></a>
								 <? } else { ?>
								       --
								 <?	} ?>
					         </td>
				        </tr>
			       	<?
	                }
	            }
	            ?>
			</table>
	    <? endif;
	}?>

	<?
    $flDispensaPreliminar = false;
    foreach($coberturasAdicionais as $cobertura){
        if($cobertura['fl_vistoria_preliminar'] == 1){
            $flDispensaPreliminar = true;
        }
    }
    if($coberturaPrincipal['fl_vistoria_preliminar'] == 1){
        $flDispensaPreliminar = true;
    }

	/* só exibe para funcionários da AgroBrasil */
    if($User->id_empresa == 20 && $flDispensaPreliminar == true):?>
	<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
		<tr>
			<td>
				<b>Vistoria Preliminar:</b>&nbsp;&nbsp;
				Dispensada&nbsp;
				<input type="checkbox" name="fl_dispensa_preliminar" id="fl_dispensa_preliminar" <?=($this->aviso->fl_dispensa_preliminar ? 'checked="checked"' : '')?> />
			</td>
		</tr>
	</table>
    <? endif; ?>

	<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
		<tr>
			<td colspan="2"><b>SEGURADO:</b></td>
		</tr>
		<tr>
			<td><b>Nome:</b>&nbsp; <?=$proponente['ds_nome_proponente']?></td>
			<td><b>CPF:</b>&nbsp; <?=$proponente['cpf_cnpj']?></td>
		</tr>
		<tr>
			<td colspan="2"><b>Fones contato:</b>&nbsp;<?=($proponente['ds_tel_residencia'] ? $proponente['ds_tel_residencia'] : "").
    													($proponente['ds_tel_celular'] ? ", ".$proponente['ds_tel_celular'] : "").
														($proponente['ds_tel_propriedade'] ? ", ".$proponente['ds_tel_propriedade'] : "")?></td>
		</tr>
		<? if (count($pessoa_autorizada) != 0): ?>
			<tr>
				<td bgcolor="#FFFFFF" colspan="2"><b>AUTORIZADOS:</b></td>
			</tr>
	        	<? foreach($pessoa_autorizada as $pessoa): ?>
	        			<tr>
							<td><?='<b>Nome:</b> '.$pessoa['ds_pessoa_autorizada']?></td>
							<td><?='<b>CPF:</b> '.$pessoa['cpf_cnpj']?></td>
						</tr>
						<tr>
							<td colspan="2"><?='<b>Telefone:</b> '.$pessoa['ds_telefone']?></td>
						</tr>
	       		<? endforeach; ?>
		<? endif; ?>
	</table>

	<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
		<tr>
			<td colspan="4"><b>PROPRIEDADE:</b></td>
		</tr>
		<tr>
			<td colspan="3"><b>Município:</b>&nbsp;<?=$propriedade['ds_nome_municipio']?></td>
			<td><b>UF:</b>&nbsp;<?=$propriedade['ds_sigla']?></td>
		</tr>
		<tr>
			<td><b>Endereço:</b>&nbsp;<?=$propriedade['ds_endereco']?></td>
			<td><b>No.:</b>&nbsp;<?=$propriedade['ds_endereco_nro']?></td>
			<td><b>Compl.</b>&nbsp;<?=$propriedade['ds_endereco_complemento']?></td>
			<td><b>Bairro:</b>&nbsp;<?=$propriedade['ds_endereco_bairro']?></td>
		</tr>
		<tr>
			<td colspan="4"><b><?=(strtotime($this->dados['vigencia']) >= strtotime('2016-01-01') ? 'Dica de acesso à Sede' : 'Ref. para Localização') ?></b>&nbsp;<?=$propriedade['ds_referencia_localizacao']?></td>
		</tr>
		<tr>
			<td colspan="4"><b>Coordenadas sede:</b>&nbsp;<?=$propriedade['ds_coordenadas']?>&nbsp;
        	<? if ($propriedade['ds_coordenadas']){
        	   		$stCoordenada = str_replace(" ,", "", $propriedade['ds_coordenadas']);
        			$stCoordenada = str_replace(",", "", $stCoordenada);
        			$stCoordenada = str_replace("-", "", $stCoordenada);
        			$arCoordenada = explode(" ",$stCoordenada);
        	} ?>
			</td>
		</tr>
	</table>

	<table width="100%" cellpading="0" cellspacing="1" class="gadget">
		<tr><td><b>CARÊNCIA PARA INÍCIO DE VIGÊNCIA DA COBERTURA DOS RISCOS</b></td></tr>
		<tr>
			<td>
				<? if (is_array($carencia)): ?>
					<b>
					<? foreach ($carencia as $cobertura): ?>
						<?=$cobertura['ds_condicao_especial']."<br />"?>
					<? endforeach; ?>
					</b>
				<? endif; ?>
			</td>
		</tr>
	</table>

    <? if ($observacoes): ?>
        <?// if ($Acl->isAllowed($this->module, 'observacao')): ?>
        <table width="100%" cellpadding="0" cellspacing="1" class="gadget">
				<tr bgcolor="#FFFFFF">
					<td align="left"><b>OBSERVAÇÕES ADICIONAIS À PROPOSTA</b></td>
				</tr>
				<tr>
					<td><?=$observacoes['ds_observacao'];?>&nbsp;</td>
				</tr>
            </table>
        <?// endif; ?>
    <? endif; ?>

	<?
 	$ocultarItensSegurados = false;
	foreach ($this->informacoesAdicionais as $observacao) {
	    if ($observacao['fl_ocultar_itens_segurados'] == true) {
	        $ocultarItensSegurados = true;
	    }
	}

	if ($ocultarItensSegurados == false) {
        $this->unidadesViewAviso($this->proposta, true, array('visualizacao'=>'avisosinistro'));
        $this->unidadesViewAviso($this->proposta, false, array('visualizacao'=>'avisosinistro'));
	}
	?>

    <? if(count($croquis)): ?>
        <? foreach ($croquis as $index => $croqui): ?>
            <?=$this->headerProposta($this->proposta, 1, 1, true) ?>
            <? list($list) = getimagesize(PATH_CROQUI."/".$croqui['ds_nome_arquivo']); ?>
            <table width="100%" cellpadding="0" cellspacing="1" class="gadget" bgcolor="#999999">
                <thead>
                    <tr>
                        <th bgcolor="#F0F0F0">Anexos 2 - Croqui <?=$index+1?></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td bgcolor="#FFFFFF" align="center"><img src="/agronet/file/croqui/name/<?=$croqui['ds_nome_arquivo']?>" width="<?=($list > 600 ? 600 : $list)?>"/></td>
                    </tr>
                </tbody>
            </table>
        <? endforeach; ?>
    <? endif; ?>

	<!--  FORMULARIO PARA ACEITAÇÃO DE AVISO DE SINISTRO CASO O MESMO ESTEJA PENDENTE -->

    <div class="no-print">
    	<form class="formDefault" name="formAceitacaoAviso" id="formAceitacaoAviso" method="post">
			<input type="hidden" name="dadosGravados" id="dadosGravados" value="<?=$this->dadosGravados?>">

			<? if ($this->data['ds_chave_status'] == 'PENDENTE' && $this->adminView):?>
				<table width="100%" cellpadding="0" cellspacing="1" class="gadget" bgcolor="#999999">
					<thead>
						<tr>
							<th width="100%" align="center" colspan="4">Informações Adicionais da Proposta</th>
						</tr>
					</thead>
					<tbody>

					    <? if($this->proposta->cliente()): ?>
						<tr>
							<td bgcolor="#FFFFFF"><b>Cliente:</b> <?=$this->proposta->cliente(); ?></td>
						</tr>
						<? endif; ?>

						<tr>
							<td bgcolor="#FFFFFF">
								<input type="hidden" name="dt_sinistro" value="<?=Agro_Util::formatDate($dataHoraSinistro[0], Zend_Date::DATES)?>">
								<input type="hidden" name="status_aviso" id="status_aviso" value="">
								<input type="hidden" name="idEmpresaProcesso" id="idEmpresaProcesso" value="<?=$this->idEmpresaProcesso?>">
								<?=$this->form->id_proposta?>
								<?=$this->form->id_processo?>
								<?=$this->form->id_aviso?>

								<table width="100%" cellspacing="1" cellpadding="0" class="grid_gray">
									<thead>
										<tr>
											<th width="50%" align="center">Aceitar Aviso</td>
											<th width="50%" align="center">Recusar Aviso</td>
										</tr>
									</thead>
									<tbody>
										<tr valign="top">
											<td>
												<? if ($this->form->id_processo->getValue()): ?>
													<?=$this->message('Esta Proposta já possui Processo de Sinistro: '.$this->form->id_processo->getValue(), 'alert');?>
												<? endif; ?>

												<? if ($this->vistoriadoraByCpfCnpjNome): ?>
													<?=$this->message('O segurado de CPF/CNPJ nro.'.$proponente['cpf_cnpj'].' já possuiu uma proposta sinistrada e encaminhada para a empresa '.$this->vistoriadoraByCpfCnpjNome, 'alert');?>
												<? endif; ?>

												<? if (count($this->data['arAvisosExistentes']) > 0): ?>
													<?=$this->message('Esta proposta já possui aviso para um sinistro ocorrido na mesma data.', 'alert');?>
													<table width="100%" cellspacing="1" cellpadding="0" class="grid_gray">
														<thead>
															<tr>
																<th align="center">Aviso</td>
																<th align="center">Dt. Sinistro</td>
																<th align="center">Status</td>
															</tr>
														</thead>
														<tbody>
															<?foreach($this->data['arAvisosExistentes'] as $AvisoAnterior):?>
																<tr>
																	<td align="center"><?=$AvisoAnterior['id']?></td>
																	<td align="center"><?=$AvisoAnterior['dt_sinistro']?></td>
																	<td align="center"><?=$AvisoAnterior['ds_status']?></td>
																</tr>
															<?endforeach?>
														</tbody>
													</table>
												<?endif?>

												<div class="row" style="display:table; margin-top: 5px;">
													<?=$this->form->empresas?>
												</div>
											</td>
											<td>
												<div class="row"><?=$this->form->motivo_recusa?></div>
											</td>
										</tr>
										<tr>
											<td>
												<input type="button" name="enviar" id="btnEnviar" value="Enviar aviso à empresa vistoriadora">
											</td>
											<td>
												<input type="button" name="recusar" id="btnRecusar" value="Recusar Aviso">
											</td>
										</tr>
									</tbody>
								</table>

								<div class="jqmWindow no-print" id="listVistoriasPendentes">
									<?=$this->title('Vistorias Pendentes')?>
									<div class="geral">
										<div class="no-print" style="overflow:auto; height: 200px; width: 500px" id="div_vistorias_pendentes"></div>
										<div>
											<input type="button" id="btnSalvarVistorias" value="Ok" />
											&nbsp;&nbsp;
											<input type="button" id="btnFecharVistoriasPendentes" value="Fechar" />
										</div>
									</div>
									<hr style="clear:both;" />
								</div>
							</td>
						</tr>
					</tbody>
				</table>
			<? endif; ?>
		</form>
    </div>
</div>


