<div class="content-add01">
	<div class="heading01"><h1>Liste des demandes 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_cart_filter') ?>
			<?php echo select_tag('filter_status', options_for_select(KataoCartPeer::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::getAllUsersGroupedByNode(), $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_cart_filter_reset') ?>">[annuler]</a></div>
		</form>
	</div>
	<div class="filter-right">&nbsp;</div>
</div>

<?php if (empty($katao_cartList)): ?>
	<p>Aucune demande.</p>
<?php else : ?>
     <?php echo link_to('Supprimer les demandes sélectionnées (' . multiple_action_info_selected('katao_cart') . ')', '@katao_cart_delete_multiple', array('class' => 'delete', 'confirm' => 'Êtes-vous sûr de vouloir supprimer les demandes sélectionnées ?')) ?>
     <span class="pdf">Exporter les demandes : </span><?php echo link_to('toutes', '@katao_cart_export_pdf_all') ?> | <?php echo link_to('sélectionnées (' . multiple_action_info_selected('katao_cart') . ')', '@katao_cart_export_pdf_selected') ?>
  	 <?php echo link_to('Générer les commandes fournisseurs', '@katao_cart_generate_orders', array('class' => 'order')) ?>
  <table class="admin-list">
    <tr>
	  <th nowrap="nowrap" width="1%"><?php echo multiple_action_checkbox_all('katao_cart') ?></th>
	  <th nowrap="nowrap">N&deg; <?php echo sort_links($sf_request, 'no', 'kataoCart/index') ?></th>
	  <th nowrap="nowrap">Date <?php echo sort_links($sf_request, 'date', 'kataoCart/index') ?></th>
	  <th nowrap="nowrap">Etat <?php echo sort_links($sf_request, 'status', 'kataoCart/index') ?></th>
	  <th nowrap="nowrap">Adhérent <?php echo sort_links($sf_request, 'member', 'kataoCart/index') ?></th>
	  <th nowrap="nowrap">Montant</th>
	  <th nowrap="nowrap">Noeud <?php echo sort_links($sf_request, 'node', 'kataoCart/index') ?></th>
	  <th nowrap="nowrap">Période <?php echo sort_links($sf_request, 'period', 'kataoCart/index') ?></th>
	  <th width="1%">Actions</th>
	</tr>
	<?php foreach ($katao_cartList as/*(KataoCart)*/ $katao_cart): ?>
		<?php $katao_cart_products = $katao_cart->getKataoCartProductsOrderByProductName() ?>
    <?php

        $total = 0;
    $katao_cart_products_data = array();
    foreach ($katao_cart_products as/*(KataoCartProduct)*/ $katao_cart_product) {
        $quantity_asked = $katao_cart_product->getQuantity();
        $quantity_adjusted = $katao_cart_product->gethasBeenAdjusted()?$katao_cart_product->getQuantityAdjusted():CONST_N_A;
        $quantity_delivered = $katao_cart_product->getKataoOrderProduct()?($katao_cart_product->getKataoOrderProduct()->getHasBeenDelivered()?$katao_cart_product->getQuantityDelivered():CONST_N_A):CONST_N_A;

        $quantity = $quantity_delivered;
        if (CONST_N_A === $quantity) {
            $quantity = $quantity_adjusted;
        }
        if (CONST_N_A === $quantity) {
            $quantity = $quantity_asked;
        }

        $price = $katao_cart_product->getProductPriceWithTaxes();
        $sub_total = $quantity * $price;
        $total += $sub_total;

        $katao_cart_products_data[] = array('product_name' => $katao_cart_product->getProductName(),
            'quantity_asked' => $quantity_asked,
            'quantity_adjusted' => $quantity_adjusted,
            'quantity_delivered' => $quantity_delivered,
            'price' => $price,
            'sub_total' => $sub_total,
            );
    }

    ?>

    <tr valign="top" class="line">
		  <td class="center"><?php echo multiple_action_checkbox_line('katao_cart', $katao_cart->getId()) ?></td>
		  <td nowrap="nowrap">
			<a href="javascript://" onclick="toggleDetails('<?php echo $katao_cart->getId() ?>');" title="Détails"><?php echo image_tag('actions/expand.png', array('alt' => 'Détails', 'id' => 'cart-icon-' . $katao_cart->getId(), 'align' => 'bottom')) ?></a>
			<?php echo $katao_cart->getNumber() ?>
		  </td>
		  <td nowrap="nowrap"><?php echo $katao_cart->getCreatedAtStr() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_cart->getStatusStr() ?></td>
		  <td><?php echo $katao_cart->getMemberLink() ?></td>
		  <td nowrap="nowrap" style="text-align:right!important"><?php echo Utils::formatCurrencyEuro($total) ?></td>
		  <td nowrap="nowrap"><?php echo $katao_cart->getNodeLink() ?></td>
		  <td nowrap="nowrap"><?php echo $katao_cart->getPeriodLink() ?></td>
		  <td nowrap="nowrap">
	<?php if (KataoCart::STATUS_IN_PROGRESS == $katao_cart->getStatus()): ?>
		<?php echo catalyz_link_to_image_tag('@katao_cart_validate?id=' . $katao_cart->getId(), 'actions/validate.png', array('title' => 'Valider', 'confirm' => 'Êtes-vous sûr de vouloir valider cette demande ?'), array('alt' => 'Valider')) ?>
	<?php elseif (KataoCart::STATUS_VALIDATED == $katao_cart->getStatus()): ?>
		<?php echo catalyz_link_to_image_tag('@katao_cart_unvalidate?id=' . $katao_cart->getId(), 'actions/unvalidate.png', array('title' => 'Dé-valider', 'confirm' => 'Êtes-vous sûr de vouloir dé-valider cette demande ?'), array('alt' => 'Dé-valider')) ?>
	<?php endif ?>
		<?php echo catalyz_link_to_image_tag('@katao_cart_pdf?id=' . $katao_cart->getId(), 'actions/pdf.png', array('title' => 'Exporter en PDF'), array('alt' => 'Exporter en PDF')) ?>
	    <?php echo catalyz_link_to_image_tag('@katao_cart_delete?id=' . $katao_cart->getId(), 'actions/delete.png', array('title' => 'Supprimer', 'confirm' => 'Êtes-vous sûr de vouloir supprimer cette demande ?'), array('alt' => 'Supprimer')) ?>
	  </td>
	</tr>
	<tr valign="top" style="display: none" id="cart-details-<?php echo $katao_cart->getId() ?>">
	  <td colspan="9">
	  <?php if(0 == count($katao_cart_products)): ?>
	  	<p>Aucun produit.</p>
	  <?php else: ?>
	  	<table class="admin-sub-list">
	  	<tr>
	  		<th>Produit</th>
			<th nowrap="nowrap" width="1%"><?php echo image_tag('actions/cart.png', array('alt' => 'Quantité demandée', 'title' => 'Quantité demandée')) ?></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%">P.U. TTC</th>
	  		<th nowrap="nowrap" width="1%">Total TTC</th>
		</tr>
        <?php foreach($katao_cart_products_data as $katao_cart_product_infos): ?>
		<tr valign="top">
	  		<td><?php echo $katao_cart_product_infos['product_name'] ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo $katao_cart_product_infos['quantity_asked'] ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo $katao_cart_product_infos['quantity_adjusted'] ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo $katao_cart_product_infos['quantity_delivered'] ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($katao_cart_product_infos['price']) ?></td>
	  		<td nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($katao_cart_product_infos['sub_total']) ?></td>
		</tr>
		<?php endforeach ?>
		<tr>
			<td style="border:none!important">&nbsp;</td>
			<th colspan="4" nowrap="nowrap" style="text-align:right!important">MONTANT TOTAL TTC</th>
			<th nowrap="nowrap" style="text-align:right!important"><?php echo utils::formatCurrencyEuro($total) ?></th>
		</tr>
		</table>
	  <?php endif ?>
	  </td>
	</tr>
  <?php endforeach ?>
  </table>
  <?php echo pager($pager, sprintf('kataoCart/index?sort=%s%s', $sf_request->getParameter('sort', 'date'), $sf_request->hasParameter('desc')?'&desc=on':''), 'katao_cart') ?>
<?php endif ?>

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

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

/* ]]> */
</script>