<?php
    $dailySum = $this->transaction_model->totalDaily();
    $dailyTotal = $dailySum && $dailySum->total>0 ? $dailySum->total : 0;
    $dailyAmount = $dailySum && $dailySum->amount>0 ? $dailySum->amount : 0;
    $paidSum = $this->transaction_model->totalPaid();
    $paidTotal = $paidSum && $paidSum->total>0 ? $paidSum->total : 0;
    $paidAmount = $paidSum && $paidSum->amount>0 ? $paidSum->amount : 0;
    $unpaidSum = $this->transaction_model->totalUnpaid();
    $unpaidTotal = $unpaidSum ? $unpaidSum->total : 0;
    $unpaidAmount = $unpaidSum ? $unpaidSum->amount : 0;
    $cancelledSum = $this->transaction_model->totalCancelled();
    $cancelledTotal = $cancelledSum ? $cancelledSum->total : 0;
    $cancelledAmount = $cancelledSum ? $cancelledSum->amount : 0;

    $ws = $we = date('Y-m-d');
    aclGetWeek($ws, $we);
    $ws = $ws . ' 00:00:00';
    $we = $we . ' 23:59:59';

    $totalAmount = $this->transaction_model->totalDateStatusWiseAmount($ws, $we);
    $totalAmount = $totalAmount ? $totalAmount->amount : 0;

    $wpaidAmount = $this->transaction_model->totalDateStatusWiseAmount($ws, $we, 'Y');
    $wpaidAmount = $wpaidAmount ? $wpaidAmount->amount : 0;

    $wunpaidAmount = $this->transaction_model->totalDateStatusWiseAmount($ws, $we, 'N');
    $wunpaidAmount = $wunpaidAmount ? $wunpaidAmount->amount : 0;

    $wcancelledAmount = $this->transaction_model->totalDateStatusWiseAmount($ws, $we, 'C');
    $wcancelledAmount = $wcancelledAmount ? $wcancelledAmount->amount : 0;

    $paidPercentage = $totalAmount>0 && $wpaidAmount>0 ? aclCalculatePercentage($totalAmount, $wpaidAmount) : 0;
    $unpaidPercentage = $totalAmount>0 && $wunpaidAmount>0 ? aclCalculatePercentage($totalAmount, $wunpaidAmount) : 0;
    $cancelledPercentage = $totalAmount>0 && $wcancelledAmount>0 ? aclCalculatePercentage($totalAmount, $wcancelledAmount) : 0;
?>
<div class="row">
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
        <div class="info-box bg-blue">
            <div class="icon">
                <i class="material-icons">monetization_on</i>
            </div>
            <div class="content">
                <div class="text">TODAY TRANSACTION</div>
                <div class="number"><span class="count-to" data-from="0" data-to="<?php echo $dailyTotal ?>" data-speed="1000" data-fresh-interval="20"><?php echo $dailyTotal ?></span> / <span class="count-to-float" data-from="0" data-to="<?php echo $dailyAmount ?>" data-speed="1000" data-fresh-interval="20"><?php echo $dailyAmount ?></span> ৳</div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
        <div class="info-box bg-green">
            <div class="icon">
                <i class="material-icons">check_circle</i>
            </div>
            <div class="content">
                <div class="text">TOTAL PAID</div>
                <div class="number"><span class="count-to" data-from="0" data-to="<?php echo $paidTotal ?>" data-speed="1000" data-fresh-interval="20"><?php echo $paidTotal ?></span> / <span class="count-to-float" data-from="0" data-to="<?php echo $paidAmount ?>" data-speed="1000" data-fresh-interval="20"><?php echo $paidAmount ?></span> ৳</div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
        <div class="info-box bg-red">
            <div class="icon">
                <i class="material-icons">error</i>
            </div>
            <div class="content">
                <div class="text">TOTAL PENDING</div>
                <div class="number"><span class="count-to" data-from="0" data-to="<?php echo $unpaidTotal ?>" data-speed="1000" data-fresh-interval="20"><?php echo $unpaidTotal ?></span> / <span class="count-to-float" data-from="0" data-to="<?php echo $unpaidAmount ?>" data-speed="1000" data-fresh-interval="20"><?php echo $unpaidAmount ?></span> ৳</div>
            </div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
        <div class="info-box bg-grey">
            <div class="icon">
                <i class="material-icons">remove_circle</i>
            </div>
            <div class="content">
                <div class="text">TOTAL CANCELLED</div>
                <div class="number"><span class="count-to" data-from="0" data-to="<?php echo $cancelledTotal ?>" data-speed="1000" data-fresh-interval="20"><?php echo $cancelledTotal ?></span> / <span class="count-to-float" data-from="0" data-to="<?php echo $cancelledAmount ?>" data-speed="1000" data-fresh-interval="20"><?php echo $cancelledAmount ?></span> ৳</div>
            </div>
        </div>
    </div>
</div>
<div class="row clearfix">
    <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>Transaction Summary</h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <div class="btn-group btn-group-sm btn-period-chooser  pull-right" role="group" aria-label="...">
                            <button type="button" class="btn btn-default acl-change-chart active" acl-type="today">Today</button>
                            <button type="button" class="btn btn-default acl-change-chart" acl-type="month">This Month</button>
                            <button type="button" class="btn btn-default acl-change-chart" acl-type="year">This Year</button>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="body"><iframe class="chartjs-hidden-iframe" style="width: 100%; display: block; border: 0px; height: 0px; margin: 0px; position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;"></iframe>
                <canvas id="line_chart" height="269" width="539" style="display: block; width: 539px; height: 269px;"></canvas>
            </div>
        </div>
    </div>
    <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>Weekly Summary</h2>
            </div>
            <div class="body">
                <div id="donut_chart" class="graph"></div>
            </div>
        </div>
    </div>
</div>
<?php $label = array(); $data = array(); if($this->transaction_model->generateTodaySummary( $label,$data )) : ?>
<script type="text/javascript">
        var aclChartConfig = {
            type: 'line',
            data: {
                labels: <?php echo @json_encode($label) ?>,
                datasets: [{
                    label: "Unpaid",
                    data: <?php echo @json_encode($data[0]) ?>,
                    borderColor: 'rgba(216, 58, 47, 0.75)',
                    backgroundColor: 'rgba(244, 67, 54, 0.4)',
                    pointBorderColor: 'rgba(216, 58, 47, 0)',
                    pointBackgroundColor: 'rgba(216, 58, 47, 0.9)',
                    pointBorderWidth: 1
                },{
                    label: "Paid",
                    data: <?php echo @json_encode($data[1]) ?>,
                    borderColor: 'rgba(65, 153, 69, 0.75)',
                    backgroundColor: 'rgba(75, 175, 80, 0.4)',
                    pointBorderColor: 'rgba(65, 153, 69, 0)',
                    pointBackgroundColor: 'rgba(65, 153, 69, 0.9)',
                    pointBorderWidth: 1
                },
                    {
                        label: "Total",
                        data: <?php echo @json_encode($data[2]) ?>,
                        borderColor: 'rgba(83, 110, 121, 0.75)',
                        backgroundColor: 'rgba(96, 125, 139, 0.4)',
                        pointBorderColor: 'rgba(83, 110, 121, 0)',
                        pointBackgroundColor: 'rgba(83, 110, 121, 0.9)',
                        pointBorderWidth: 1
                    }]
            }
        };
    </script>
<?php endif; ?>
<?php if(($paidPercentage+$unpaidPercentage+$cancelledPercentage) == '100' ) : ?>
    <script type="text/javascript">
        var aclDonutData = [{
            label: 'Unpaid',
            value: <?php echo $unpaidPercentage ?>
        }, {
            label: 'Paid',
            value: <?php echo $paidPercentage?>
        },  {
            label: 'Cancelled',
            value: <?php echo $cancelledPercentage?>
        }]
    </script>
<?php endif; ?>
