<?
$this->showPrint = true;
?>

<link rel="stylesheet" href="/resources/css/sinistro/cobrancaprint.css" type="text/css" media="print" />
<link rel="stylesheet" href="/resources/css/sinistro/cobrancaview.css" type="text/css" media="screen" />

<div class="content">
	<? $this->headerCobranca($this->id,$this->tipoRelatorio);
	?>

		<table class='grid2' cellspacing='1' cellpadding='0' border='0' id='tablePagination'>
			<thead>
				<tr>
					<th colspan="<?=($this->tipoRelatorio == 'F' ? 13 : 12);?>" align="center" nowrap="nowrap">Honorários</th>
					<th colspan="3" id="separator" align="center"></th>
					<th colspan="2" align="center">Kilometragem</th>
					<th id="separator" align="center"></th>
					<th colspan="4" align="center" nowrap="nowrap">Despesas</th>
				</tr>
			</thead>
			<thead>
				<tr>
					<th align="center" nowrap="nowrap">Data</th>
					<th align="center" nowrap="nowrap">Proposta</th>
					<th align="center" nowrap="nowrap">Processo</th>
					<?=($this->tipoRelatorio == 'F' ? '<th align="center" nowrap="nowrap">Proc. Seg.</th>' : '');?>
					<th align="center" nowrap="nowrap">Segurado</th>
					<th align="center" nowrap="nowrap">Município</th>
					<th align="center" nowrap="nowrap">UF</th>
					<th align="center" nowrap="nowrap">Cultura</th>
					<th width="80px" align="center" nowrap="nowrap">Talhão</th>
					<th align="center" nowrap="nowrap">Variedade</th>
					<th align="center" nowrap="nowrap">Vistoria</th>
					<th align="center" nowrap="nowrap">Área Vistoriada</th>
					<th align="center" nowrap="nowrap">R$</th>
					<th id="separator" align="center" nowrap="nowrap">&nbsp;</th>
					<th align="center" nowrap="nowrap">Perito</th>
					<th width="20px" id="separator" align="center" nowrap="nowrap">&nbsp;</th>
					<th align="center" nowrap="nowrap">Km</th>
					<th align="center" nowrap="nowrap">R$</th>
					<th id="separator" align="center" nowrap="nowrap">&nbsp;</th>
					<th align="center" nowrap="nowrap">Pedágio</th>
					<th align="center" nowrap="nowrap">Hotel</th>
					<th align="center" nowrap="nowrap">Alimentação</th>
					<th align="center" nowrap="nowrap">Total</th>
				</tr>
			</thead>
			<tbody>

				<?

				$i = 0;
				foreach($this->dados as $registro):
					if ($i % 2 == 0) {
						$class = '';
					} else {
						$class = "highlight";
					}

					if($registro['tipoRelatorio'] == 'Previa' || $registro['tipoRelatorio'] == 'Prévia' || $registro['tipoRelatorio'] == 'P'){
						$ModelPrevia = new Sinistro_Model_CobrancaPrevia();
						$itensVariedades = $ModelPrevia->getItensVariedade($registro['id_vistoria'],$registro['ds_safra']);
						$itens = $itensVariedades['itens'];
						$variedade = $itensVariedades['variedade'];
						$tipoRelatorio = 'Prévia';
					}else{
						$itens = $registro['itens'];
						$variedade = $registro['variedade'];
					}

					//valores da nota
					$notaTotalHonorarios = $registro['vl_total_honorarios'];
					$notaTotalCustoKm = $registro['vl_total_quilometragem'];
					$notaTotalDespesas = $registro['vl_total_despesas'];
					$notaTotalDespesasEKm = ($registro['vl_total_despesas'] + $registro['vl_total_quilometragem']);
					$notaTotalKmRodada += $registro['vl_quilometragem'];
					$notaTotalPedagio += $registro['vl_pedagio'];
					$notaTotalHotel += $registro['vl_hotel'];
					$notaTotalAlimentacao += $registro['vl_alimentacao'];

					//valor total da nota fiscal
					//$valorTotalNotaFiscal = $notaTotalHonorarios+$notaTotalDespesasEKm;

					//total despesas da vistoria (pedagio+hotel+alimentacao)
					$vistoriaTotalDespesas = ($registro['vl_hotel']+$registro['vl_pedagio']+$registro['vl_alimentacao'])

					?>

					<tr class="<?= $class; ?>">
						<td align="center"><?=Agro_Util::formatDate($registro['dt_vistoria'],Zend_Date::DATES);?></td>
						<td align="center"><?=$registro['id_proposta']; ?></td>
						<td align="center"><?=$registro['id_processo']; ?></td>
						<?=($this->tipoRelatorio == 'F' ? '<td align="center">'.$registro['id_processo_seguradora'].'</td>' : '');?>
						<td align="left"><?=$registro['ds_nome_proponente'];?></td>
						<td align="left"><?=$registro['ds_nome_municipio'];?></td>
						<td align="center"><?=$registro['ds_sigla'];?></td>
						<td align="left"><?=$registro['ds_nome_cultura'];?></td>
						<td align="center"><?=$itens;?></td>
						<td align="center"><?=$variedade;?></td>
						<td align="center"><?=$registro['tp_vistoria'];?></td>

						<td align="center"><?=Agro_Util::formatDbCurrency($registro['itensAreaTotal']);?></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($registro['vistoriaTotalHonorarios']);?></td>
						<td id="separator"></td>
						<td align="right"><?=$registro['perito'];?></td>
						<td id="separator"></td>
						<td align="center"><?=Agro_Util::formatDbCurrency($registro['vl_quilometragem']);?></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($registro['vl_custo_quilometragem']);?></td>
						<td id="separator"></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($registro['vl_pedagio']);?></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($registro['vl_hotel']);?></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($registro['vl_alimentacao']);?></td>
						<td align="right"><?=Agro_Util::formatDbCurrency($vistoriaTotalDespesas);?></td>

					</tr>
				<?
				$i++;
				endforeach;

				?>
				<tr id="top">
					<td colspan="<?=($this->tipoRelatorio == 'F' ? 10 : 9);?>" class="highlight">
					</td>
					<td colspan="2" align="center">
					Total de Honorários
					</td>
					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalHonorarios);?></strong></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td align="center"><strong><?=Agro_Util::formatDbCurrency($notaTotalKmRodada,0);?></strong></td>
					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalCustoKm);?></strong></td>
					<td colspan="1">&nbsp;</td>

					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalPedagio);?></strong></td>
					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalHotel);?></strong></td>
					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalAlimentacao);?></strong></td>
					<td align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalDespesas);?></strong></td>

				</tr>
				<tr valign="middle">
					<td colspan="15" align="center">Espaço Reservado para Assinatura e Carimbo
						<div id="carimbo"></div>
					</td>
					<td colspan="7">
						<table id="totais">
							<tr>
								<td>Reembolso de Despesas</td>
								<td id="right" align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalDespesas);?></strong></td>
							</tr>
							<tr>
								<td>Quilometragem</td>
								<td id="right" align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalCustoKm);?></strong></td>
							</tr>
							<tr>
								<td>Total de Despesas e km</td>
								<td id="right" align="right"><strong><?=Agro_Util::formatDbCurrency($notaTotalDespesasEKm);?></strong></td>
							</tr>
							<!-- <tr>
								<td>Total da Nota Fiscal</td>
								<td id="right" align="right"><strong><?=Agro_Util::formatDbCurrency($valorTotalNotaFiscal);?></strong></td>
							</tr> -->
						</table>
					</td>
				</tr>
			</tbody>

		</table>
</div>
