<style>
    .table-month td { width: 8.333%; }
    .table-month tr:first-child td { text-align:center; }
    .table-month tr:last-child td { text-align:right; }
    .info-box {
        box-shadow: 0 0 1px rgba(0,0,0,.125), 0 1px 3px rgba(0,0,0,.2);
        border-radius: .25rem;
        background: #fff;
    }
    .info-box .info-box-content:hover{
        cursor: pointer;
        color: #7e949a!important;
    }
</style>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box" style="border-top: 2.5px solid #004785;">
                <!--div class="box-header">
                   
                </div-->
                <div class="box-body">
                    <div class="col-sm-12">
                        <div class="row">
                            <div class="col-md-3 col-sm-6 col-xs-12" data-toggle="modal" data-target="#modalComprobantesMensuales">
                                <div class="info-box" style="background-color: #f9eac5;">
                                   <span class="info-box-icon" style="color: #f9c74f;background-color: #f9eac5;"><i class="fa fa-shopping-cart"></i></span>
                                    <div class="info-box-content" style="color: #2E6171;">
                                        <span class="info-box-text"><?= lang('sales_value'); ?></span>
                                        <span class="info-box-number"><?= "S/ " . $this->tec->formatMoney($total_sales->total_amount) ?></span>
                                        <div class="progress">
                                            <div style="width: 100%;background-color: #f9c74f;" class="progress-bar"></div>
                                        </div>
                                        <span class="progress-description">
                                            <?= $total_sales->total .' ' . lang('sales'); ?> |
                                            <?= $this->tec->formatMoney($total_sales->paid) . ' ' . lang('received') ?> |
                                            <?= $this->tec->formatMoney($total_sales->tax) . ' ' . lang('tax') ?>
                                        </span>
                                    </div>
                                </div>
                            </div>
<!-- ============================================================ -->
                            <div class="modal fade" id="modalComprobantesMensuales" tabindex="-1" role="dialog" aria-labelledby="modalComprobantesMensualesLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                        <h5 class="modal-title" id="modalComprobantesMensualesLabel">TOTAL DE COMPROBANTES EMITIDOS - <?=$year;?></h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        </div>
                                        <div class="modal-body">
                                            <table class="table" align="left">
                                                <thead>
                                                    <tr>
                                                        <th>TIPO COMPROBANTE</th>
                                                        <th>CANTIDAD</th>
                                                        <th>IMPORTE</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                <?php foreach ($comprobantes_mensuales as $comprobantesItem) { ?>
                                                    <tr>
                                                        <td><?=$comprobantesItem->tipo_comprobante ?></td>
                                                        <td><?=$comprobantesItem->cantidad_comprobantes ?></td>
                                                        <td><?="S/. ".$this->tec->formatMoney($comprobantesItem->grand_total) ?></td>
                                                    </tr>
                                                <?php } ?>
                                                
                                            </tbody>
                                            </table>
                                        </div>
                                        <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
<!-- ============================================================ -->
                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="info-box" style="background-color: #d1efba;">
                                   <span class="info-box-icon" style="color: #90be6d;background-color: #d1efba;"><i class="fa fa-plus"></i></span>
                                    <div class="info-box-content" style="color: #2E6171;">
                                        <span class="info-box-text"><?= lang('purchases_value'); ?></span>
                                        <span class="info-box-number"><?= "S/ " . $this->tec->formatMoney($total_purchases->total_amount) ?></span>
                                        <div class="progress">
                                            <div style="width: 100%;background-color: #90be6d;" class="progress-bar"></div>
                                        </div>
                                        <span class="progress-description">
                                            <?= $total_purchases->total ?> <?= lang('purchases'); ?>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="info-box" style="background-color: #a7e8d5;">
                                   <span class="info-box-icon" style="color: #43aa8b;background-color: #a7e8d5;"><i class="fa fa-circle-o"></i></span>
                                    <div class="info-box-content" style="color: #2E6171;">
                                        <span class="info-box-text"><?= lang('expenses_value'); ?></span>
                                        <span class="info-box-number"><?= "S/ " . $this->tec->formatMoney($total_expenses->total_amount) ?></span>
                                        <div class="progress">
                                            <div style="width: 100%;background-color: #43aa8b;" class="progress-bar"></div>
                                        </div>
                                        <span class="progress-description">
                                            <?= $total_expenses->total ?> <?= lang('expenses'); ?>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6 col-xs-12">
                                <div class="info-box" style="background-color: #a7c9e8;">
                                   <span class="info-box-icon" style="color: #577590;background-color: #a7c9e8;"><i class="fa fa-dollar"></i></span>
                                    <div class="info-box-content" style="color: #2E6171;">
                                        <span class="info-box-text"><?= lang('profit_loss'); ?></span>
                                        <span class="info-box-number"><?= "S/ " . $this->tec->formatMoney($total_sales->total_amount-$total_purchases->total_amount-$total_expenses->total_amount) ?></span>
                                        <div class="progress">
                                            <div style="width: 100%;background-color: #577590;" class="progress-bar"></div>
                                        </div>
                                        <span class="progress-description">
                                            <?= $total_sales->total_amount.' - '.$total_purchases->total_amount.' - '.$total_expenses->total_amount;?>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="calendar table-responsive">

                            <table class="table table-month table-bordered" style="min-width:522px;">
                                <thead>
                                    <tr class="active">
                                        <th><div class="text-center"> <a href="<?= site_url('reports/monthly_sales/'.($year-1)); ?>">&lt;&lt;</a> </div></th>
                                        <th colspan="10"><div class="text-center"> <?php echo $year; ?> </div></td>
                                            <th><div class="text-center"> <a href="<?= site_url('reports/monthly_sales/'.($year+1)); ?>">&gt;&gt;</a> </div></th>
                                        </th>
                                    </tr>
                                </thead>
                                <tr>
                                    <td><?= lang('cal_january'); ?></td>
                                    <td><?= lang('cal_february'); ?></td>
                                    <td><?= lang('cal_march'); ?></td>
                                    <td><?= lang('cal_april'); ?></td>
                                    <td><?= lang('cal_mayl'); ?></td>
                                    <td><?= lang('cal_june'); ?></td>
                                    <td><?= lang('cal_july'); ?></td>
                                    <td><?= lang('cal_august'); ?></td>
                                    <td><?= lang('cal_september'); ?></td>
                                    <td><?= lang('cal_october'); ?></td>
                                    <td><?= lang('cal_november'); ?></td>
                                    <td><?= lang('cal_december'); ?></td>
                                </tr>
                                <tr>
                                    <?php
                                    if(!empty($sales)) {

                                        foreach($sales as $value) {
                                            $array[$value->date] = "<span class='text-warning'>". $value->tax."</span><br>".$value->discount."<br><span class='text-success'>".$value->total."</span><br><span style='border-top:1px solid #DDD; display:block;'>".$value->grand_total."</span>";
                                        }

                                        for ($i = 1; $i <= 12; $i++){
                                            echo "<td>";
                                            if(isset($array[$i])) {
                                                echo $array[$i];
                                            } else {
                                                echo "<span class='text-warning'>0.00</span><br>0.00<br><span class='text-success'>0.00</span><br><span style='border-top:1px solid #DDD;display:block;'>0.00</span>";
                                            }
                                            echo "</td>";
                                        }

                                    } else {
                                        for($i=1; $i<=12; $i++) {
                                            echo "<td><span class='text-warning'>0.00</span><br>0.00<br><span class='text-success'>0.00</span><br><span style='border-top:1px solid #DDD;display:block;'>0.00</span></td>";
                                        }
                                    }
                                    ?>
                                </tr>
                            </table>
                        </div>
                        <h4 class="box-title"><span class='text-warning'><?=$this->lang->line('tax')?> = <?= lang('orange'); ?></span>, <?=$this->lang->line('discount')?> = <?= lang('grey'); ?> &amp; <span class='text-success'><?=$this->lang->line('total')?> = <?= lang('green'); ?></span></h4>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
