<div class="content-add01">
	<div class="heading01"><h1>Liste des factures fournisseurs (<?php echo $pager->getNbResults() ?>)</h1></div>
</div>

<div class="filter">
	<div class="filter-left">&nbsp;</div>
	<div class="filter-middle">
		<?php echo form_tag('@katao_supplier_invoice_filter') ?>
			<?php echo select_tag('filter_status', options_for_select(KataoSupplierInvoicePeer::getAllStatuses(), $filter_status, array('include_custom' => '&mdash;&nbsp;Etat&nbsp;&mdash;'))) ?>
			<?php echo image_tag('separator02.gif', array('alt' => '')) ?>&nbsp;<?php echo select_tag('filter_supplier', options_for_select(KataoSupplierPeer::getAllSimple(), $filter_supplier, array('include_custom' => '&mdash;&nbsp;Fournisseur&nbsp;&mdash;'))) ?>
			<?php echo image_tag('separator02.gif', array('alt' => '')) ?>&nbsp;<?php echo select_tag('filter_period', options_for_select(KataoPeriodPeer::getAll(), $filter_period, array('include_custom' => '&mdash;&nbsp;Période&nbsp;&mdash;'))) ?>
			<?php echo submit_tag('', array('class' => 'btn-search', 'title' => 'Filtrer')) ?><div style="float:right"><a href="<?php echo url_for('@katao_supplier_invoice_filter_reset') ?>">[annuler]</a></div>
		</form>
	</div>
	<div class="filter-right">&nbsp;</div>
</div>

<?php if (empty($katao_supplier_invoiceList)): ?>
	<p>Aucune facture.</p>
	<p><?php echo link_to('Ajouter une facture', '@katao_supplier_invoice_add', array('class' => 'add')) ?></p>
<?php else : ?>
  <?php echo link_to('Ajouter une facture', '@katao_supplier_invoice_add', array('class' => 'add')) ?>
  <?php echo link_to('Supprimer les factures sélectionnées (' . multiple_action_info_selected('katao_supplier_invoice') . ')', '@katao_supplier_invoice_delete_multiple', array('class' => 'delete', 'confirm' => 'Êtes-vous sûr de vouloir supprimer les factures sélectionnées ?')) ?>
  <span class="pdf">Exporter les factures : </span><?php echo link_to('toutes', '@katao_supplier_invoice_export_pdf_all') ?> | <?php echo link_to('sélectionnées (' . multiple_action_info_selected('katao_supplier_invoice') . ')', '@katao_supplier_invoice_export_pdf_selected') ?>
  <table class="admin-list">
    <tr>
	  <th nowrap="nowrap" width="1%"><?php echo multiple_action_checkbox_all('katao_supplier_invoice') ?></th>
	  <th nowrap="nowrap">Réf. <?php echo sort_links($sf_request, 'reference', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap">Date <?php echo sort_links($sf_request, 'date', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap">Etat <?php echo sort_links($sf_request, 'status', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap">Fournisseur <?php echo sort_links($sf_request, 'supplier', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap">Montant <?php echo sort_links($sf_request, 'total', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap">Période <?php echo sort_links($sf_request, 'period', 'kataoSupplierInvoice/index') ?></th>
	  <th nowrap="nowrap" width="1%">Actions</th>
	</tr>
	<?php foreach ($katao_supplier_invoiceList as/*(KataoSupplierInvoice)*/ $katao_supplier_invoice): ?>
    <tr valign="top" class="line">
		  <td class="center"><?php echo multiple_action_checkbox_line('katao_supplier_invoice', $katao_supplier_invoice->getId()) ?></td>
		  <td nowrap="nowrap">
			<a href="javascript://" onclick="toggleDetails('<?php echo $katao_supplier_invoice->getId() ?>');" title="Détails"><?php echo image_tag('actions/expand.png', array('alt' => 'Détails', 'id' => 'supplier-invoice-icon-' . $katao_supplier_invoice->getId(), 'align' => 'bottom')) ?></a>
			<?php echo $katao_supplier_invoice->getReference() ?>
		  </td>
		  <td nowrap="nowrap"><?php echo $katao_supplier_invoice->getInvoiceDateStr() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_supplier_invoice->getStatusStr() ?></td>
		  <td><?php echo $katao_supplier_invoice->getSupplierName() ?></td>
		  <td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($katao_supplier_invoice->getTotalHt() + $katao_supplier_invoice->getTotalTva()) ?></td>
		  <td nowrap="nowrap"><?php echo $katao_supplier_invoice->getKataoPeriod()->getName() ?></td>
		  <td nowrap="nowrap">
		<?php echo catalyz_link_to_image_tag('@katao_supplier_invoice_export_pdf?id=' . $katao_supplier_invoice->getId(), 'actions/pdf.png', array('title' => 'Exporter en PDF'), array('alt' => 'Exporter en PDF')) ?>
	<?php if (KataoSupplierInvoice::STATUS_RECEIVED == $katao_supplier_invoice->getStatus()): ?>
		<?php echo catalyz_link_to_image_tag('@katao_supplier_invoice_edit?id=' . $katao_supplier_invoice->getId(), 'actions/edit.png', array('title' => 'Modifier'), array('alt' => 'Modifier')) ?>
		<?php echo catalyz_link_to_image_tag('@katao_supplier_invoice_pay?id=' . $katao_supplier_invoice->getId(), 'actions/pay.png', array('title' => 'Payer'), array('alt' => 'Payer')) ?>
	<?php endif ?>
	    <?php echo catalyz_link_to_image_tag('@katao_supplier_invoice_delete?id=' . $katao_supplier_invoice->getId(), 'actions/delete.png', array('title' => 'Supprimer', 'confirm' => 'Êtes-vous sûr de vouloir supprimer cette facture ?'), array('alt' => 'Supprimer')) ?>
	  </td>
	</tr>
	<tr valign="top" style="display: none" id="supplier-invoice-details-<?php echo $katao_supplier_invoice->getId() ?>">
	  <td colspan="9">
		<table class="admin-sub-list">
	  	<tr>
	  		<th>Produit</th>
			<th nowrap="nowrap" width="1%">Qté</th>
	  		<th nowrap="nowrap" width="1%">P.U. HT</th>
	  		<th nowrap="nowrap" width="1%">Montant HT</th>
	  		<th nowrap="nowrap" width="1%">TVA</th>
		</tr>
		<?php foreach ($katao_supplier_invoice->getKataoSupplierInvoiceProducts() as/*(KataoSupplierInvoiceProduct)*/ $katao_supplier_invoice_product): ?>
			<?php $quantity = $katao_supplier_invoice_product->getQuantity() ?>
			<?php $price = $katao_supplier_invoice_product->getProductPriceEuro() ?>
			<?php $sub_total = $katao_supplier_invoice_product->getProductPriceTotal() ?>
		<tr valign="top">
	  		<td><?php echo $katao_supplier_invoice_product->getProductName() ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo $quantity ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($price) ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($sub_total) ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo 100 * $katao_supplier_invoice_product->getProductTvaRate() ?>%</td>
		</tr>
		<?php endforeach ?>
		</table>

		<?php $tva_rates = array('0.2' => 1, '0.055' => 2, '0' => 0) ?>
		<?php $total_by_tva_rate = array('0.2' => 0, '0.055' => 0, '0' => 0) ?>

		<table class="admin-sub-list">
		<tr valign="top">
		 	<td rowspan="<?php echo count($tva_rates) + 2 ?>" width="97%" style="border:none!important;padding-left:15px">
		 		<p><u>Commande(s) concernée(s)</u> : <?php echo $katao_supplier_invoice->getOrdersStr() ?></p>
			<?php if ('' != $katao_supplier_invoice->getComment()): ?>
				<p><u>Observations</u> : <?php echo $katao_supplier_invoice->getComment() ?></p>
			<?php endif ?>
			<?php if (KataoSupplierInvoice::STATUS_PAID == $katao_supplier_invoice->getStatus()): ?>
				<p><u>Paiement</u> : le <?php echo CatalyzDate::formatShort($katao_supplier_invoice->getPaymentDate(null)) ?> par <?php echo $katao_supplier_invoice->getPaymentModeStr() ?><?php echo ('' != $katao_supplier_invoice->getPaymentDetails())?sprintf(' (%s)', $katao_supplier_invoice->getPaymentDetails()):'' ?></p>
			<?php endif ?>
			</td>
			<th nowrap="nowrap" width="1%">Taux</th>
		 	<th nowrap="nowrap" width="1%" style="text-align:right!important">Bases HT</th>
		 	<th nowrap="nowrap" width="1%" style="text-align:right!important">Remises HT</th>
		 	<th nowrap="nowrap" width="1%" style="text-align:right!important">Montant</th>
		</tr>
		<?php $with_taxes_total = 0 ?>
		<?php $without_taxes_total = 0 ?>
		<?php $tva_total = 0 ?>
		<?php foreach ($total_by_tva_rate as $tva_rate => $tva_rate_total): ?>
			<?php $getTauxBasesHt = sprintf('getTaux%dBasesHt', $tva_rates[(string)$tva_rate]) ?>
			<?php $tva_rate_total = $katao_supplier_invoice->$getTauxBasesHt() ?>

			<?php $getTauxDiscountHt = sprintf('getTaux%dDiscountHt', $tva_rates[(string)$tva_rate]) ?>
			<?php $tva_rate_discount = $katao_supplier_invoice->$getTauxDiscountHt() ?>

			<?php $getTauxAmount = sprintf('getTaux%dAmount', $tva_rates[(string)$tva_rate]) ?>
			<?php $total_by_tva_rate2 = $katao_supplier_invoice->$getTauxAmount() ?>

			<?php $without_taxes_total += $tva_rate_total ?>
			<?php $tva_total += round($tva_rate_total * $tva_rate, 2) ?>
		<tr>
		 	<td nowrap="nowrap" style="text-align:right!important"><?php echo 100 * $tva_rate ?>%</td>
		 	<td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($tva_rate_total) ?></td>
		 	<td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($tva_rate_discount) ?></td>
		 	<td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($total_by_tva_rate2) ?></td>
		</tr>
		<?php endforeach ?>
		<tr>
			<th>Total</th>
			<td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($katao_supplier_invoice->getReference()?$katao_supplier_invoice->getTotalHt():round($without_taxes_total, 2)) ?></td>
			<td>&nbsp;</td>
			<td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($katao_supplier_invoice->getReference()?$katao_supplier_invoice->getTotalTva():round($tva_total, 2)) ?></td>
		</tr>
		</table>
	  </td>
	</tr>
  <?php endforeach ?>
  </table>
  <?php echo pager($pager, sprintf('kataoSupplierInvoice/index?sort=%s%s', $sf_request->getParameter('sort', 'date'), $sf_request->hasParameter('desc')?'&desc=on':''), 'katao_supplier_invoice') ?>
<?php endif ?>

<script type="text/javascript" language="JavaScript">
/* <![CDATA[ */

function toggleDetails( id ){
	$('supplier-invoice-details-'+id).toggle();
	if($('supplier-invoice-details-'+id).visible()) {
		$('supplier-supplier-invoice-icon-'+id).src = '<?php echo image_path('actions/collapse.png') ?>';
	} else {
		$('supplier-supplier-invoice-icon-'+id).src = '<?php echo image_path('actions/expand.png') ?>';
	}
}

/* ]]> */
</script>
