<?php $members_total = 0 ?>
<?php foreach ($members_count_by_node as $node_id => $node_infos): ?>
	<?php $members_total += $node_infos['members_count'] ?>
<?php endforeach ?>

<div class="content-add01">
	<div class="heading01"><h1>Nombre d'adhérents : <?php echo $members_total ?></h1></div>
</div>
<ul>
<?php foreach ($members_count_by_node as $node_id => $node_infos): ?>
	<li><?php echo $node_infos['name'] ?> : <?php echo $node_infos['members_count'] ?></li>
	<?php $members_total += $node_infos['members_count'] ?>
<?php endforeach ?>
</ul>

<?php $invoices_total = 0 ?>
<?php foreach ($invoices_sum_by_period_and_node as $period_id => $period_infos): ?>
	<?php $invoices_total += $period_infos['amount'] ?>
<?php endforeach ?>

<div class="content-add01">
	<br /><div class="heading01"><h1>Flux monétaire : <?php echo Utils::formatCurrencyEuro($invoices_total) ?></h1></div>
</div>
<?php foreach ($invoices_sum_by_period_and_node as $period_id => $period_infos): ?>
	<?php if (KataoPeriod::STATUS_ACTIVE == $period_infos['status']): ?>
		<p>Pour la période active "<?php echo $period_infos['name'] ?>" : <?php echo Utils::formatCurrencyEuro($period_infos['amount']) ?></p>
		<ul>
		<?php foreach ($period_infos['nodes_list'] as $node_id => $node_infos): ?>
			<li><?php echo $node_infos['name'] ?> : <?php echo Utils::formatCurrencyEuro($node_infos['amount']) ?></li>
		<?php endforeach ?>
		</ul>
	<?php endif ?>
<?php endforeach ?>

<div class="content-add01">
	<br /><div class="heading01"><h1>Montant des demandes de la période active :</h1></div>
</div>

<table class="admin-sub-list">
<tbody>
<tr>
	<th>Noeud</th>
	<th><?php echo image_tag('actions/unvalidate.png', array('alt' => 'Non validés', 'align' => 'top')) ?>&nbsp;Non validés</th>
	<th><?php echo image_tag('actions/validate.png', array('alt' => 'Validées', 'align' => 'top')) ?>&nbsp;Validées</th>
	<th>Total</th>
</tr>
<?php $total_unvalidated = 0 ?>
<?php $total_validated = 0 ?>
<?php foreach (KataoCartPeer::getAmountStats() as $katao_node_city => $katao_node_amounts): ?>
<?php $total_unvalidated += $katao_node_amounts['unvalidated'] ?>
<?php $total_validated += $katao_node_amounts['validated'] ?>
<tr>
	<td><?php echo $katao_node_city ?></td>
	<td><?php echo Utils::formatCurrencyEuro($katao_node_amounts['unvalidated']) ?></td>
	<td><?php echo Utils::formatCurrencyEuro($katao_node_amounts['validated']) ?></td>
	<td><?php echo Utils::formatCurrencyEuro($katao_node_amounts['unvalidated'] + $katao_node_amounts['validated']) ?></td>
</tr>
<?php endforeach ?>
<tr>
	<th>TOTAL</th>
	<th><?php echo Utils::formatCurrencyEuro($total_unvalidated) ?></th>
	<th><?php echo Utils::formatCurrencyEuro($total_validated) ?></th>
	<th><?php echo Utils::formatCurrencyEuro($total_unvalidated + $total_validated) ?></th>
</tr>
</tbody>
</table>

<div class="content-add01">
	<br /><div class="heading01"><h1>Exporter les écritures pour la comptabilité :</h1></div>
</div>
<?php if($active_period): ?>
<form name="export" action="<?php echo url_for('@katao_period_export_accounting') ?>" method="post">
	<?php echo label_for('date_from', 'Du :') ?><?php echo input_date_tag('date_from', $active_period->getBeginAt(), Utils::getInputDateTagOptions()) ?>
	&nbsp;<?php echo label_for('date_to', 'Au :') ?><?php echo input_date_tag('date_to', $active_period->getFinishAt(), Utils::getInputDateTagOptions()) ?>
	&nbsp;<?php echo submit_tag('Exporter') ?>
</form>
<?php endif; ?>
<div class="content-add01">
	<br /><div class="heading01"><h1>Produits dont le tarif HT est incorrect :</h1></div>
</div>

<?php $katao_products = array() ?>
<?php $katao_products_all = KataoProductPeer::getAll() ?>
<?php foreach ($katao_products_all as/*(KataoProduct)*/ $katao_product): ?>
	<?php $price_ht_1 = round($katao_product->getUnitPriceEuro(), 3) ?>
	<?php $price_ht_2 = round($katao_product->getUnitPriceEuroCalculated(), 3) ?>
	<?php if ($price_ht_1 != $price_ht_2): ?>
		<?php $katao_products[$katao_product->getId()] = array('product' => $katao_product->getName(), 'price_ht_1' => $price_ht_1, 'price_ht_2' => $price_ht_2) ?>
	<?php endif ?>
<?php endforeach ?>

<?php if (0 < count($katao_products)): ?>

<p>
	Résumé : <?php echo count($katao_products) ?> incorrects / <?php echo count($katao_products_all) ?> total
	<br /><?php echo link_to('Ajuster tous les prix HT automatiquement', '@katao_product_price_adjust', array('class' => 'adjust', 'confirm' => 'Êtes-vous sûr de vouloir ajuster automatiquement les prix HT de ces ' . count($katao_products) . ' produits ?')) ?>
</p>

<table class="admin-sub-list">
<tbody>
<tr>
	<th>Produit</th>
	<th>Tarif HT saisi</th>
	<th>Tarif HT calculé</th>
	<th>Ecart</th>
	<th>Action</th>
</tr>
<?php foreach ($katao_products as $katao_product_id => $katao_product_data): ?>
<tr>
	<td><?php echo $katao_product_data['product'] ?></td>
	<td><?php echo $katao_product_data['price_ht_1'] ?> €</td>
	<td><?php echo $katao_product_data['price_ht_2'] ?> €</td>
	<td><?php echo abs(round($katao_product_data['price_ht_1'] - $katao_product_data['price_ht_2'], 3)) ?> €</td>
	<td><?php echo catalyz_link_to_image_tag('@katao_product_edit?id=' . $katao_product_id, 'actions/edit.png', array('title' => 'Modifier'), array('alt' => 'Modifier')) ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</ul>

<?php else: ?>

<p>Aucun produit.</p>

<?php endif ?>
