<?php

class Seguro_View_Helper_BoxCobrancaDefault extends Zend_View_Helper_Abstract {
	
	public function boxCobrancaDefault($Proposta, $isMpdf = false) {
		if ($isMpdf) {
			$this->boxCobrancaDefaultPrint($Proposta);
			return;
		}

		$cobranca = $Proposta->cobranca();
		?>
		<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
			<thead>
				<tr>
					<th colspan="2">Informações de Cobrança</th>
				</tr>
			</thead>
			<tbody>
				<tr>
				    <? $parcelas = $cobranca['parcelamento'];	?>
					<td nowrap="nowrap" width="18%"><label>Condição Comercial</label><?=count($parcelas); ?>x</td>
					<td rowspan="5" valign="top">
						<? if (count($parcelas)): ?>
							<table width="100%" cellpadding="1" cellspacing="0" class="gadget">
								<thead>
									<tr>
										<th width="1%">Nº</th>
										<th width=19%><label>Prêmio Líquido</label></th>
										<th width=25%><label>Prêmio Previsto<br>Subvenção Estadual</label></th>
										<th width=25%><label>Prêmio Previsto<br>Subvenção Federal</label></th>
										<th width=20%><label>Prêmio Previsto Proponente</label></th>
										<th width=10%><label>Vencimento</label></th>
									</tr>
								</thead>
								<tbody>
									<? foreach ($parcelas as $parcela): ?>
										<?
										if ($parcela['nr_parcela'] == 1){
											$parcela['vl_total'] -= $Proposta['vl_custo_apolice'];
										} 
										$fl_pago = ($parcela['fl_pago_parcela'] ? 'Sim' : 'Não');
										?>
										<tr>
											<td class="border_gray" align="center"><?=$parcela['nr_parcela']?>&nbsp;</td>
											<td class="border_gray" align="center"><?=Agro_Util::formatDbCurrency($parcela['vl_total'])?>&nbsp;</td>
											<td class="border_gray" align="center"><?=Agro_Util::formatDbCurrency($parcela['vl_subvencao_estadual'])?>&nbsp;</td>
											<td class="border_gray" align="center"><?=Agro_Util::formatDbCurrency($parcela['vl_subvencao_federal'])?>&nbsp;</td>
											<td class="border_gray" align="center"><?=Agro_Util::formatDbCurrency($parcela['vl_segurado'])?>&nbsp;</td>
											<td class="border_gray" align="center"><?=Agro_Util::formatDate($parcela['dt_vencimento'], Zend_Date::DATES)?>&nbsp;</td>
										</tr>
									<? endforeach; ?>
								</tbody>
							</table>
						<? endif; ?>
					</td>
				</tr>
				<tr>
					<td id="td_vl_premio_liquido">
            <label>Prêmio Líquido</label><?=Agro_Util::formatDbCurrency($cobranca['premio_liquido']);?>&nbsp
          </td>
				</tr>
				<tr>
					<td id="td_vl_custo_apolice">
            <label>Custo de Apólice</label><?=Agro_Util::formatDbCurrency($Proposta['vl_custo_apolice'])?>&nbsp;
          </td>
				</tr>
				<tr>
					<td><label>IOF</label><?=$cobranca['iof']?>&nbsp;</td>
				</tr>
				<tr>
					<td id="td_vl_premio_pagar">
            <label>Prêmio a Pagar</label><?=Agro_Util::formatDbCurrency($cobranca['premio_liquido'] + $Proposta['vl_custo_apolice']);?>&nbsp;
          </td>
				</tr>
			</tbody>
		</table>
		<?
	}
	
	private function boxCobrancaDefaultPrint($Proposta) {
		$cobranca = $Proposta->cobranca();
		?>
		<table width="100%" cellpadding="0" cellspacing="1" class="gadget">
			<thead>
				<tr>
					<th colspan="2" style="background-color: white;">Informações de Cobrança</th>
				</tr>
			</thead>
			<tbody>
				<tr>
				    <? $parcelas = $cobranca['parcelamento'];	?>
					<td nowrap="nowrap" width="18%" style=""><div><span style="font-weight: bold;">Condição Comercial</span></div><?=count($parcelas); ?>x</td>
					<td rowspan="5" valign="top">
						<? if (count($parcelas)): ?>
							<table width="100%" cellpadding="1" cellspacing="0" class="gadget">
								<thead>
									<tr>
										<th width="5%" style="background-color: white;"><span style="font-weight: bold;">Nº</span></th>
										<th width=15%  style="background-color: white;"><span style="font-weight: bold;">Prêmio Líquido</span></th>
										<th width=25%  style="background-color: white;"><span style="font-weight: bold;">Prêmio Previsto<br>Subvenção Estadual</span></th>
										<th width=25%  style="background-color: white;"><span style="font-weight: bold;">Prêmio Previsto<br>Subvenção Federal</span></th>
										<th width=20%  style="background-color: white;"><span style="font-weight: bold;">Prêmio Previsto Proponente</span></th>
										<th width=10%  style="background-color: white;"><span style="font-weight: bold;">Vencimento</span></th>
									</tr>
								</thead>
								<tbody>
									<? foreach ($parcelas as $parcela): ?>
										<?
										if ($parcela['nr_parcela'] == 1){
											$parcela['vl_total'] -= $Proposta['vl_custo_apolice'];
										} 
										$fl_pago = ($parcela['fl_pago_parcela'] ? 'Sim' : 'Não');
										?>
										<tr>
											<td class="border_gray" align="center" ><?=$parcela['nr_parcela']?>&nbsp;</td>
											<td class="border_gray" align="center" ><?=Agro_Util::formatDbCurrency($parcela['vl_total'])?>&nbsp;</td>
											<td class="border_gray" align="center" ><?=Agro_Util::formatDbCurrency($parcela['vl_subvencao_estadual'])?>&nbsp;</td>
											<td class="border_gray" align="center" ><?=Agro_Util::formatDbCurrency($parcela['vl_subvencao_federal'])?>&nbsp;</td>
											<td class="border_gray" align="center" ><?=Agro_Util::formatDbCurrency($parcela['vl_segurado'])?>&nbsp;</td>
											<td class="border_gray" align="center" ><?=Agro_Util::formatDate($parcela['dt_vencimento'], Zend_Date::DATES)?>&nbsp;</td>
										</tr>
									<? endforeach; ?>
								</tbody>
							</table>
						<? endif; ?>
					</td>
				</tr>
				<tr>
					<td style=""><div><span style="font-weight: bold;">Prêmio Líquido</span></div><?=Agro_Util::formatDbCurrency($cobranca['premio_liquido']);?>&nbsp;</td>
				</tr>
				<tr>
					<td style=""><div><span style="font-weight: bold;">Custo de Apólice</span></div><?=Agro_Util::formatDbCurrency($Proposta['vl_custo_apolice'])?>&nbsp;</td>
				</tr>
				<tr>
					<td style=""><div><span style="font-weight: bold;">IOF</span></div><?=$cobranca['iof']?>&nbsp;</td>
				</tr>
				<tr>
					<td style=""><div><span style="font-weight: bold;">Prêmio a Pagar</span></div><?=Agro_Util::formatDbCurrency($cobranca['premio_liquido'] + $Proposta['vl_custo_apolice']);?>&nbsp;</td>
				</tr>
			</tbody>
		</table>
		<?
	}
}
