<div class="content-add01">
	<div class="heading01"><h1>Liste des factures adhérents (<?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_invoice_filter') ?>
			<?php echo select_tag('filter_status', options_for_select(KataoInvoicePeer::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_member', options_for_select(KataoMemberPeer::getAllGroupedByNode(), $filter_member, array('include_custom' => '&mdash;&nbsp;Adhérent&nbsp;&mdash;'))) ?>
			<?php echo image_tag('separator02.gif', array('alt' => '')) ?>&nbsp;<?php echo select_tag('filter_node', options_for_select(KataoNodePeer::getAllArray(), $filter_node, array('include_custom' => '&mdash;&nbsp;Noeud&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_invoice_filter_reset') ?>">[annuler]</a></div>
		</form>
	</div>
	<div class="filter-right">&nbsp;</div>
</div>

<?php if (empty($katao_invoiceList)): ?>
	<p>Aucune facture.</p>
<?php else : ?>
  <?php echo link_to('Valider les factures', '@katao_invoice_validate', array('class' => 'validate')) ?>
  <?php echo link_to('Supprimer les factures sélectionnées (' . multiple_action_info_selected('katao_invoice') . ')', '@katao_invoice_delete_multiple', array('class' => 'delete', 'confirm' => 'Êtes-vous sûr de vouloir supprimer les factures sélectionnées ?')) ?>
  <div style="padding-top:4px">
  	<span class="pdf">Exporter les factures : </span><?php echo link_to('toutes', '@katao_invoice_export_pdf_all') ?> | <?php echo link_to('sélectionnées (' . multiple_action_info_selected('katao_invoice') . ')', '@katao_invoice_export_pdf_selected') ?>
  	<?php echo link_to('Envoyer les factures sélectionnées (' . multiple_action_info_selected('katao_invoice') . ')', '@katao_invoice_send_multiple', array('class' => 'send')) ?>
  </div>
  <table class="admin-list">
    <tr>
	  <th nowrap="nowrap" width="1%"><?php echo multiple_action_checkbox_all('katao_invoice') ?></th>
	  <th nowrap="nowrap">N&deg; <?php echo sort_links($sf_request, 'no', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap">Date <?php echo sort_links($sf_request, 'date', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap">Etat <?php echo sort_links($sf_request, 'status', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap">Adhérent <?php echo sort_links($sf_request, 'member', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap">Montant</th>
	  <th nowrap="nowrap">Noeud <?php echo sort_links($sf_request, 'node', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap">Période <?php echo sort_links($sf_request, 'period', 'kataoInvoice/index') ?></th>
	  <th nowrap="nowrap" width="1%">Actions</th>
	</tr>
	<?php foreach ($katao_invoiceList as/*(KataoInvoice)*/ $katao_invoice): ?>
    <tr valign="top" class="line">
		  <td class="center"><?php echo multiple_action_checkbox_line('katao_invoice', $katao_invoice->getId()) ?></td>
		  <td nowrap="nowrap">
			<a href="javascript://" onclick="toggleDetails('<?php echo $katao_invoice->getId() ?>');" title="Détails"><?php echo image_tag('actions/expand.png', array('alt' => 'Détails', 'id' => 'invoice-icon-' . $katao_invoice->getId(), 'align' => 'bottom')) ?></a>
			<?php echo $katao_invoice->getNumber() ?>
		  </td>
		  <td nowrap="nowrap"><?php echo $katao_invoice->getCreatedAtStr() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_invoice->getStatusStr() ?></td>
		  <td><?php echo $katao_invoice->getMemberName() ?></td>
		  <td nowrap="nowrap" style="text-align:right!important"><?php echo $katao_invoice->sumProductsStr() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_invoice->getNodeLink() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_invoice->getPeriodLink() ?></td>
		  <td nowrap="nowrap">
	    <?php echo catalyz_link_to_image_tag('@katao_invoice_pdf?id=' . $katao_invoice->getId(), 'actions/pdf.png', array('title' => 'Exporter en PDF'), array('alt' => 'Exporter en PDF')) ?>
	<?php if (KataoInvoice::STATUS_VALIDATED == $katao_invoice->getStatus()): ?>
		<?php echo catalyz_link_to_image_tag('@katao_invoice_send?id=' . $katao_invoice->getId(), 'actions/send.png', array('title' => 'Envoyer à l\'adhérent'), array('alt' => 'Envoyer à l\'adhérent')) ?>
	<?php endif ?>
	<?php if (in_array($katao_invoice->getStatus(), array(KataoInvoice::STATUS_GENERATED, KataoInvoice::STATUS_DELIVERED))): ?>
		<?php echo catalyz_link_to_image_tag('@katao_invoice_deliver?id=' . $katao_invoice->getId(), 'actions/deliver.png', array('title' => 'Délivrer'), array('alt' => 'Délivrer')) ?>
	<?php endif ?>
	    <?php echo catalyz_link_to_image_tag('@katao_invoice_delete?id=' . $katao_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="invoice-details-<?php echo $katao_invoice->getId() ?>">
	  <td colspan="9">
		<table class="admin-sub-list">
	  	<tr>
	  		<th>Produit</th>
	  		<th nowrap="nowrap" width="1%"><?php echo image_tag('actions/adjust.png', array('alt' => 'Quantité commandée', 'title' => 'Quantité commandée')) ?></th>
			<th nowrap="nowrap" width="1%"><?php echo image_tag('actions/deliver.png', array('alt' => 'Quantité délivrée', 'title' => 'Quantité délivrée')) ?></th>
	  		<th nowrap="nowrap" width="1%">Prix TTC</th>
	  		<th nowrap="nowrap" width="1%">Total</th>
		</tr>
		<?php $total = 0 ?>
		<?php foreach ($katao_invoice->getKataoInvoiceProductsOrderByProduct() as/*(KataoInvoiceProduct)*/ $katao_invoice_product): ?>
			<?php $quantity = $katao_invoice_product->getQuantity() ?>
			<?php $quantity_delivered = $katao_invoice_product->getQuantityDelivered() ?>
			<?php $price = $katao_invoice_product->getProductPriceWithTaxes() ?>
			<?php $sub_total = $quantity_delivered * $price ?>
			<?php $total += $sub_total ?>
		<tr valign="top">
	  		<td><?php echo $katao_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 (KataoInvoice::STATUS_GENERATED != $katao_invoice->getStatus())?$quantity_delivered:CONST_N_A ?></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>
		</tr>
		<?php endforeach ?>
		<tr>
			<td style="border:none!important">&nbsp;</td>
			<th colspan="3" nowrap="nowrap" style="text-align:right!important">TOTAL :</th>
			<th nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($total) ?></th>
		</tr>
		</table>
	  </td>
	</tr>
  <?php endforeach ?>
  </table>
  <?php echo pager($pager, sprintf('kataoInvoice/index?sort=%s%s', $sf_request->getParameter('sort', 'date'), $sf_request->hasParameter('desc')?'&desc=on':''), 'katao_invoice') ?>
<?php endif ?>

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

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

/* ]]> */
</script>