<?php $__env->startSection('content'); ?>
        @parent
        <?php echo $__env->make('global.status', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
        <div class="row m-t-15 widgets">
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-inverse bg-primary">
                    <div class="box bg-info text-center">
                        <h1 class="font-light text-white"><?php echo e($company->clients->count()); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.clients')); ?></h6>
                    </div>
                </div>
            </div>
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-primary bg-purple">
                    <div class="box text-center">
                        <h1 class="font-light text-white"><?php echo e($company->policies->count()); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.policies')); ?></h6>
                    </div>
                </div>
            </div>
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-inverse bg-success">
                    <div class="box text-center">
                        <h1 class="font-light text-white"><?php echo e($company->currency_symbol); ?><?php echo e($company->policies->sum('premium') + 0); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.sales')); ?></h6>
                    </div>
                </div>
            </div>
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-inverse bg-primary">
                    <div class="box text-center">
                        <h1 class="font-light text-white"><?php echo e($company->currency_symbol); ?><?php echo e($company->payments->sum('amount') + 0); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.conversions')); ?></h6>
                    </div>
                </div>
            </div>
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-inverse bg-danger">
                    <div class="box text-center">
                        <h1 class="font-light text-white"><?php echo e($company->currency_symbol); ?><?php echo e($company->payments->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                            return $count + ($broker->inviteePayments->sum('amount') * $broker->commission_rate / 100);
                        }, 0) + $company->staff->reduce(function($count, $staff) {
                            return $count + ($staff->inviteePayments->sum('amount') * $staff->commission_rate / 100);
                        }, 0))); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.income')); ?></h6>
                    </div>
                </div>
            </div>
            <!-- Column -->
            <div class="col-md-6 col-lg-2 col-xlg-2">
                <div class="card card-inverse bg-warning">
                    <div class="box text-center">
                        <h1 class="font-light text-white"><?php echo e($company->policies()->expiring('after', 30)->count()); ?></h1>
                        <h6 class="text-white"><?php echo e(trans('dashboard.counter.expiring')); ?></h6>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4 m-b-15">
                <div class="ui segment white">
                    <div class="segment-header">
                        <h3><?php echo e(trans('dashboard.graph.header.monthly')); ?></h3>
                    </div>
                    <div id="monthlySales"></div>
                </div>
            </div>
            <div class="col-md-8 m-b-15">
                <div class="ui segment white">
                    <div class="segment-header">
                        <h3><?php echo e(trans('dashboard.graph.header.annual')); ?></h3>
                    </div>
                    <div id="annualSales"></div>
                </div>
            </div>
        </div>

        <div class="ui segment white">
            <div class="segment-header">
                <h3><?php echo e(trans('dashboard.table.title')); ?></h3>
            </div>
            <table class="ui striped table">
                <thead>
                    <tr>
                        <th><?php echo e(trans('dashboard.table.header.number')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.ref_no')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.client')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.product')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.insurer')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.premium')); ?></th>
                        <th><?php echo e(trans('dashboard.table.header.due')); ?></th>
                        <th class="center aligned"><?php echo e(trans('dashboard.table.header.status')); ?></th>
                        <th class="center aligned"><?php echo e(trans('dashboard.table.header.action')); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; foreach($latest_policies as $policy): $__empty_1 = false; ?>
                    <tr class="<?php echo e($policy->statusClass); ?>">
                        <td><?php echo e($policy->id); ?></td>
                        <td><?php echo e($policy->ref_no); ?></td>
                        <td><?php echo e($policy->payer); ?></td>
                        <td class="text-ellipsis"><?php echo e($policy->product->name); ?></td>
                        <td><?php echo e($policy->product->insurer); ?></td>
                        <td><?php echo e($company->currency_symbol); ?><?php echo e($policy->premium + 0); ?></td>
                        <td><?php echo e($company->currency_symbol); ?><?php echo e($policy->premium - $policy->payments->sum('amount')); ?></td>
                        <td class="center aligned">
                            <?php if($policy->premium <= $policy->paid && $policy->paid > 0): ?>
                            <div class="ui green mini label"> <?php echo e(trans('dashboard.table.data.status.paid')); ?></div>
                            <?php elseif($policy->premium > $policy->paid && $policy->paid > 0): ?>
                            <div class="ui orange mini label"> <?php echo e(trans('dashboard.table.data.status.partial')); ?></div>
                            <?php elseif($policy->premium == $policy->paid && $policy->paid === 0): ?>
                            <div class="ui yellow mini label"> <?php echo e(trans('dashboard.table.data.status.free')); ?></div>
                            <?php else: ?>
                            <div class="ui red mini label"> <?php echo e(trans('dashboard.table.data.status.unpaid')); ?></div>
                            <?php endif; ?>
                        </td>
                        <td class="center aligned"><a href="<?php echo e(action('PolicyController@getOne', array($policy->id))); ?>" class="ui mini grey label"> <?php echo e(trans('dashboard.table.data.action')); ?> </a></td>
                    </tr>
                    <?php endforeach; if ($__empty_1): ?>
                    <tr>
                        <td colspan="9" style="text-align:center;"><?php echo e(trans('dashboard.table.data.not_available')); ?></td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extra_scripts'); ?>
    <script type="text/javascript">
        // this Month
        Morris.Donut({
            element: 'monthlySales',
            data: [
                {label: '<?php echo e(trans('dashboard.graph.label.monthly.paid')); ?>', value: <?php echo e($company->payments()->madeWithin('month')->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {label: '<?php echo e(trans('dashboard.graph.label.monthly.due')); ?>', value: <?php echo e($company->policies->sum('premium') - $company->payments->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + (($broker->inviteePolicies()->sum('premium') - $broker->inviteePayments()->sum('amount')) * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + (($staff->inviteePolicies()->sum('premium') - $staff->inviteePayments()->sum('amount')) * $staff->commission_rate / 100);
                }, 0))); ?>}
            ],
            colors: ['#21ba45','#ff0000'],
            formatter: function (x) { return '<?php echo e($company->currency_symbol); ?>' + x }
        }).on('click', function(i, row){
            console.log(i, row);
        });

        // income
        Morris.Bar({
            element: 'annualSales',
            data: [
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.jan')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '01')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '01')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '01')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.feb')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '02')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '02')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '02')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.mar')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '03')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '03')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '03')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.apr')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '04')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '04')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '04')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.may')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '05')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '05')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '05')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.jun')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '06')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '06')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '06')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.jul')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '07')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '07')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '07')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.aug')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '08')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '08')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '08')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.sep')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '09')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '09')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '09')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.oct')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '10')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '10')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '10')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.nov')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '11')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '11')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '11')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>},
                {   x: '<?php echo e(trans('dashboard.graph.label.annual.dec')); ?>', y: <?php echo e($company->payments()->madeWithin('month', '12')->get()->sum('amount') - ($company->brokers->reduce(function($count, $broker) {
                    return $count + ($broker->inviteePayments()->madeWithin('month', '12')->sum('amount') * $broker->commission_rate / 100);
                }, 0) + $company->staff->reduce(function($count, $staff) {
                    return $count + ($staff->inviteePayments()->madeWithin('month', '12')->sum('amount') * $staff->commission_rate / 100);
                }, 0))); ?>}
            ],
            xkey: 'x',
            ykeys: 'y',
            labels: ['<?php echo e(trans('dashboard.graph.pop_over.annual') . ' ' . $company->currency_symbol); ?>'],
            barColors: ['#4D7CFE'],
            resize: true
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('templates.dashboard', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>