<div class="content-add01">
	<div class="heading01"><h1>Livraison de la facture "<?php echo $katao_invoice->getNumber() ?>" de l'adhérent "<?php echo $katao_invoice->getMemberName() ?>" pour la période "<?php echo $katao_invoice->getKataoPeriod()->getName() ?>"</h1></div>
</div>

<?php echo form_tag('@katao_invoice_deliver?id=' . $katao_invoice->getId()) ?>

<table class="admin-sub-list">
<tr>
	<td style="border:none!important">&nbsp;</td>
	<th colspan="3" style="text-align:center!important">Quantités</th>
</tr>
<tr>
	<th>Produit</th>
	<th nowrap="nowrap" width="1%" style="text-align:center!important">Commandée</th>
	<th nowrap="nowrap" width="1%" style="text-align:center!important">Délivrée</th>
	<th nowrap="nowrap" width="1%" style="text-align:center!important">EN COURS / TOTAL</th>
</tr>
<?php $criteria = new Criteria();
$criteria->addAscendingOrderByColumn(KataoInvoiceProductPeer::PRODUCT_NAME); ?>
<?php foreach ($katao_invoice->getKataoInvoiceProductsJoinKataoProduct($criteria) as/*(KataoInvoiceProduct)*/ $katao_invoice_product): ?>
	<?php $katao_product = $katao_invoice_product->getKataoProduct() ?>

	<?php $quantity = $katao_invoice_product->getQuantityDelivered() ?>
	<?php $total_delivered_quantity = $katao_product->getTotalDeliveredQuantity($katao_invoice->getId(), $katao_invoice->getKataoPeriodId(), $katao_invoice->getKataoNodeId()) ?>
<tr>
 	<td><?php echo $katao_invoice_product->getProductName() ?></td>
 	<td style="text-align:center!important"><?php echo $katao_invoice_product->getQuantity() ?></td>
 	<td nowrap="nowrap" style="text-align:center!important">
 		<a href="javascript://" onclick="document.getElementById('quantity_<?php echo $katao_invoice_product->getId() ?>').value = Math.max(0, parseInt(document.getElementById('quantity_<?php echo $katao_invoice_product->getId() ?>').value) - 1); updateCurrentDelivered(<?php echo $katao_invoice_product->getId() ?>, <?php echo $total_delivered_quantity ?>);" title="Diminuer la quantité"><?php echo image_tag('minus.png', array('alt' => 'Diminuer la quantité', 'align' => 'top')) ?></a>
		<?php echo input_tag('quantity[' . $katao_invoice_product->getId() . ']', $quantity, array('style' => 'width: 20px; text-align: center;', 'class' => 'quantity-delivered', 'onchange' => 'updateCurrentDelivered(' . $katao_invoice_product->getId() . ', ' . $total_delivered_quantity . ');')) ?>
		<a href="javascript://" onclick="document.getElementById('quantity_<?php echo $katao_invoice_product->getId() ?>').value = parseInt(document.getElementById('quantity_<?php echo $katao_invoice_product->getId() ?>').value) + 1; updateCurrentDelivered(<?php echo $katao_invoice_product->getId() ?>, <?php echo $total_delivered_quantity ?>);" title="Augmenter la quantité"><?php echo image_tag('plus.png', array('alt' => 'Augmenter la quantité', 'align' => 'top')) ?></a>
	</td>
	<td style="text-align:center!important"><span id="current-quantity-<?php echo $katao_invoice_product->getId() ?>"><?php echo $total_delivered_quantity + $quantity ?></span> / <?php echo $katao_product->getTotalReceivedQuantity($katao_invoice->getKataoPeriodId(), $katao_invoice->getKataoNodeId()) ?></td>

</tr>
<?php endforeach ?>
<tr>
	<td colspan="4"><?php echo select_tag('new_product', options_for_select($katao_invoice->getOtherProducts(), false, array('include_custom' => '&mdash;&nbsp;Autre produit&nbsp;&mdash;'))) ?>&nbsp;<?php echo submit_tag('Ajouter') ?></td>
</tr>
</table>

<br /><?php echo submit_tag('Délivrer') ?> ou <a href="<?php echo url_for('kataoInvoice/index') ?>">annuler</a>

</form>

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

function updateCurrentDelivered(id, total_delivered_quantity){
	$('current-quantity-' + id).innerHTML = total_delivered_quantity + parseInt($F('quantity_' + id));
}

/* ]]> */
</script>