<?php
$this->breadcrumbs = array(
    'Blagajna' => array('index'),
    'Tabela',
);

$this->menu = array(
    array('label' => 'Novi unos', 'url' => array('create'), 'icon' => 'plus'),
    array('label' => 'Stanje', 'url' => array('stanje'), 'icon' => 'cog'),
    array('label' => 'Evidencija', 'url' => array('admin'), 'icon' => 'list'),
    array('label'=>'Tabela Po Korisnicima NEW','url'=>array('bi/report/admin'),'icon'=>'user'),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('blagajna-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Tabela Promena</h1>

<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'action' => Yii::app()->createUrl($this->route),
    'method' => 'get',
)); ?>
<div class="form-inline">
    <div class="input-prepend input-append">

        <span class="add-on">OD</span>
        <?php $form->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model' => $model,
            'attribute' => 'datum_od',
            'value' => $model->datum_od,
            'options' => array(
                'showButtonPanel' => true,
                'changeYear' => true,
                'dateFormat' => 'dd-mm-yy',
            ),
        ));; ?>


        <span class="add-on">DO</span>
        <?php $form->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model' => $model,
            'attribute' => 'datum_do',
            'value' => $model->datum_do,
            'options' => array(
                'showButtonPanel' => true,
                'changeYear' => true,
                'dateFormat' => 'dd-mm-yy',
            ),
        ));; ?>
    </div>
</div>
<div class="form-actions">
    <?php $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'submit',
        'type' => 'primary',
        'label' => 'Prikaži',
    )); ?>
</div>

<?php $this->endWidget(); ?>

<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th>Dodavanje</th>
        <?php
        foreach ($dodavanje as $promena) {
            echo "<td>" . $promena->naziv . "</td>";
        }
        ?>
        <th >Ukupno</th>

    </tr>
    </thead>
    <tbody>
    <?php $promena_suma = array(); ?>
    <?php $ukupno_ulaz = 0; ?>
    <?php foreach ($korisnici as $user) { ?>
        <tr>
            <td><?php echo $user->ime; ?> <?php echo $user->prezime; ?></td>
            <?php $korisnik_suma = 0; ?>

            <?php foreach ($dodavanje as $promena) { ?>
                <td><?php
                    $suma = $model->korisnikTipUnterval($promena->id, $user->id);
                    $korisnik_suma += $suma;
                    if (isset($promena_suma[$promena->id])) {
                        $promena_suma[$promena->id] += $suma;
                    } else $promena_suma[$promena->id] = $suma;
                    echo $suma ;
                    $ukupno_ulaz += $suma;
                    ?> din.
                </td>
            <?php } ?>
            <td><?php echo $korisnik_suma;?> din.</td>
        </tr>        <?php } ?>
    <tr class="success">
    <th>Ukupno</th>
    <?php foreach ($dodavanje as $promena) { ?>
        <td><?php echo $promena_suma[$promena->id]; ?> din.</td>
    <?php } ?>
        <td class=""><b><?php echo $ukupno_ulaz;  ?> din.</b></td>
    </tr>


    </tbody>
</table>


<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th class="info">Uzimanje</th>
        <?php
        foreach ($uzimanje as $promena) {
            echo "<td>" . $promena->naziv . "</td>";
        }
        ?>
        <th>Ukupno</th>
    </tr>
    </thead>
    <tbody>
    <?php $promena_suma = array(); ?>
    <?php $ukupno_izlaz = 0; ?>
    <?php foreach ($korisnici as $user) { ?>
        <tr>
            <td><?php echo $user->ime; ?> <?php echo $user->prezime; ?></td>
            <?php $korisnik_suma = 0; ?>

            <?php foreach ($uzimanje as $promena) { ?>
                <td><?php
                    $suma = $model->korisnikTipUnterval($promena->id, $user->id);
                    $korisnik_suma += $suma;
                    if (isset($promena_suma[$promena->id])) {
                        $promena_suma[$promena->id] += $suma;
                    } else $promena_suma[$promena->id] = $suma;
                    echo $suma ;
                    $ukupno_izlaz  += $suma; ?> din.
                </td>
            <?php } ?>
            <td ><?php echo $korisnik_suma; ?> din.</td>
        </tr>        <?php } ?>
    <tr class="success">
    <th>Ukupno</th>
    <?php foreach ($uzimanje as $promena) { ?>
        <td><?php echo $promena_suma[$promena->id]; ?> din.</td>
    <?php } ?>
        <td class=""><b><?php echo $ukupno_izlaz;  ?> din.</b></td>
    </tr>

    </tbody>
</table>

<div class="alert alert-success" role="alert"> Razlika:
    <?php  echo $ukupno_ulaz;?> + (<?php  echo $ukupno_izlaz;?>) = <?php  echo $ukupno_ulaz+$ukupno_izlaz;?> din
</div>