<?php

class Atendimento_View_Helper_HeaderPropostaAtendimento extends Zend_View_Helper_Abstract {

	public function headerPropostaAtendimento($proposta) {
		ob_start(); ?>
		
		<?
			$Status = $proposta->status();
			$Produto = $proposta->produto(true);
			$Seguradora = $Produto->seguradora();
			$Safra = $Produto->safra();
			
			foreach ($proposta->coberturas() as $cobertura){
				if ($cobertura['fl_cobertura_principal']){
					$CoberturaPrincipal = $cobertura;
				}
			}
			
			$ProdutoGeral = $Produto->produto_geral();
		?>
		
		<table width="100%" border="0" cellpadding="1" cellspacing="0">
			<tr>
				<td width="10%" align="center"><img src="/resources/imagens/agrobrasil_72_79.jpg" /></td>
				<td valign="top">
					<table width="100%" cellpadding="1" cellspacing="0" border="0">
						<tr>
							<? if (($Status->ds_chave == 'NAO_ENVIADA') or ($Status->ds_chave == 'DEVOLVIDA')): ?>
								<td colspan="3"><b>Orçamento de Seguro</b></td>
							<? else: ?>
								<td colspan="3"><b>Proposta de Seguro</b></td>
							<? endif; ?>
						</tr>
						<tr>
							<td colspan="3" class="produto">Produto: <?=$Produto->ds_nome_produto?>&reg;</td>
						</tr>
						<tr>
							<td width="50%" valign="top">
								<table width="100%" cellpadding="0" cellspacing="0" border="0">
									<tr>
										<td class="text" width="49%">Cobertura Principal: <?=$CoberturaPrincipal['ds_nome_cobertura']?></td>
									</tr>
									<tr>
										<td class="text">Seguradora: <?=$Seguradora->ds_nome_fantasia?></td>
									</tr>
									<tr>
										<td class="text">CNPJ: <?=$Seguradora->cpf_cnpj?></td>
									</tr>
									<tr>
										<td class="text_underline">Processo SUSEP: <?=$Produto->nr_susep?></td>
									</tr>
									<tr>
										<? $this->view->doc =  $ProdutoGeral->id_ramo.'.'.$Produto->id_seguradora.'.'.$Produto->id.'.'.$proposta->id.'-'.$proposta->nr_digito_verificador?>
										
										<? if (($Status->ds_chave == 'NAO_ENVIADA') or ($Status->ds_chave == 'DEVOLVIDA')): ?>
											<td class="text_bold">Orçamento: <?=$this->view->doc?></td>
										<? else: ?>
											<td class="text_bold">Proposta: <?=$this->view->doc?></td>
										<? endif; ?>
									</tr>
									<? if ($proposta->nr_apolice): ?>
										<tr>
											<td class="text_bold">Apólice: <?=$proposta->nr_apolice?></td>
										</tr>
									<? endif; ?>
								</table>
							</td>
							<td width="50%" valign="top">
								<? if (($Status->ds_chave == 'NAO_ENVIADA') or ($Status->ds_chave == 'DEVOLVIDA')): ?>
									<table width="100%" cellpadding="1" cellspacing="0" border="0">
										<tr>
											<td class="text_uppercase">Orçamento sem cobertura</td>
										</tr>
										<tr>
											<td class="text_bold">Data Orçamento: <?=Agro_Util::formatDate($proposta->dt_criacao, Zend_Date::DATES);?></td>
										</tr>
										<tr>
											<td class="text_bold">Safra: <?=$Safra->ds_nome_safra?></td>
										</tr>
										<tr>
											<td class="text"></td>
										</tr>
									</table>
								<? else: ?>
									<table width="100%" cellpadding="1" cellspacing="0" border="0">
										<tr>
											<td class="text_bold" >Vigência</td>
										</tr>
										<tr>
											<td class="text" >Das 24 horas do dia <?=Agro_Util::formatDate($proposta->dt_vigencia_inicio, Zend_Date::DATES);?></td>
										</tr>
										<tr>
											<td class="text_underline">Até as 24 horas do dia <?=Agro_Util::formatDate($proposta->dt_vigencia_fim, Zend_Date::DATES);?></td>
										</tr>
										<tr>
											<td class="text"><?=($proposta->id_proposta_renovada ? ' <b>(Renovação)</b>' : '')?></td>
										</tr>
										<tr>
											<td class="text_bold" >Safra: <?=$Safra->ds_nome_safra?></td>
										</tr>
										<? if ($Status->ds_chave  == 'PROPOSTA_CANCELADA' || $Status->ds_chave  == 'APOLICE_CANCELADA'): ?>
											<tr>
												<td class="text_bold" style="color:<?="#".$Status->ds_cor?>" colspan="2">Status da Proposta: <?=strtoupper(strtr($Status->ds_chave ,"áéíóúâêôãõàèìòùç","ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"))?></td>
											</tr>
										<? endif; ?>
									</table>
								<? endif; ?>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		
		<?
		$html = ob_get_contents();
		ob_end_clean();
		
		return $html;
	}
}