<?php $__env->startSection('content'); ?>
    <?php
        use Carbon\Carbon;

        $companyId = !auth()->user()->hasRole('Superadmin') ? auth()->user()->employee->compnay_id : null;
        $totalPurchaseDueAmount = $companyId
            ? App\Models\Invoice::where('type', 'purchase')->where('company_id', $companyId)->sum('due_amount')
            : App\Models\Invoice::where('type', 'purchase')->sum('due_amount');
        $totalSaleDueAmount = $companyId
            ? App\Models\Invoice::where('type', 'sale')->where('company_id', $companyId)->sum('due_amount')
            : App\Models\Invoice::where('type', 'sale')->sum('due_amount');
        $totalPurchaseAmount = $companyId
            ? App\Models\Invoice::where('type', 'purchase')->where('company_id', $companyId)->sum('total_amount')
            : App\Models\Invoice::where('type', 'purchase')->sum('total_amount');
        $totalSaleAmount = $companyId
            ? App\Models\Invoice::where('type', 'sale')->where('company_id', $companyId)->sum('total_amount')
            : App\Models\Invoice::where('type', 'sale')->sum('total_amount');
        $customers = $companyId
            ? App\Models\Party::where('is_distributor', '1')->where('company_id', $companyId)->count()
            : App\Models\Party::where('is_distributor', '1')->count();
        $suppliers = $companyId
            ? App\Models\Party::where('is_supplier', '1')->where('company_id', $companyId)->count()
            : App\Models\Party::where('is_supplier', '1')->count();
        $purchaseInvoices = $companyId
            ? App\Models\Invoice::where('type', 'purchase')->where('company_id', $companyId)->count()
            : App\Models\Invoice::where('type', 'purchase')->count();
        $saleInvoices = $companyId
            ? App\Models\Invoice::where('type', 'sale')->where('company_id', $companyId)->count()
            : App\Models\Invoice::where('type', 'sale')->count();
        $totalUsers = \DB::table('users')->count();
        $totalCompanies = \DB::table('companies')->count();
        $totalBranches = \DB::table('branches')->count();
        $user_id = auth()->id();
        $company_Id = App\Models\Employee::where('id', $user_id)->count();
        $totalInvoices = \DB::table('invoices')->where('company_id', $company_Id)->count();
        $totalSuppliers = \DB::table('parties')->where('company_id', $company_Id)->where('is_supplier', 1)->count();
        $totalFranchisers = \DB::table('parties')
            ->where('company_id', $company_Id)
            ->where('is_distributor', 1)
            ->count();
        $store_issue_requisitions = \DB::table('store_issue_requisitions')->where('company_id', $company_Id)->count();
        $raw_material_items = \DB::table('raw_material_items')->where('company_id', $company_Id)->count();
        $totalCompaniesThisMonth = \DB::table('companies')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', Carbon::now()->month)
            ->count();
        $totalBranchesThisMonth = \DB::table('branches')
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', Carbon::now()->month)
            ->count();
        $totalproductsThisMonth = \DB::table('products')
            ->where('company_id', $company_Id)
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', Carbon::now()->month)
            ->count();
        $totalInvoicesThisMonth = \DB::table('invoices')
            ->where('company_id', $company_Id)
            ->whereYear('created_at', Carbon::now()->year)
            ->whereMonth('created_at', Carbon::now()->month)
            ->count();
    ?>


    <div class="row">
        <?php if (\Illuminate\Support\Facades\Blade::check('role', 'Superadmin')): ?>
            <div class="col-lg-4 col-sm-6 col-12">
                <div class="dash-widget dash3">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/company.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"></span><?php echo e($totalCompanies); ?></h5>
                        <h6>Total companies</h6>
                    </div>
                    
                </div>
            </div>
            <div class="col-lg-4 col-sm-6 col-12">
                <div class="dash-widget dash1">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/branch.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalBranches); ?></span></h5>
                        <h6>Total branches<br></h6>
                    </div>
                    
                </div>
            </div>
            <div class="col-lg-4 col-sm-6 col-12">
                <div class="dash-widget dash3">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/company.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalBranchesThisMonth); ?></span>
                        </h5>
                        <h6>Total companies - This month</h6>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 col-sm-6 col-12">
                <div class="dash-widget dash1">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/branch.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalCompaniesThisMonth); ?></span>
                        </h5>
                        <h6>Total branches - This month</h6>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 col-sm-6 col-12">
                <div class="dash-widget dash2">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/users.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalUsers); ?></span>
                        </h5>
                        <h6>Total users</h6>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 col-sm-6 col-12">
            </div>
        <?php endif; ?>
        <?php if (\Illuminate\Support\Facades\Blade::check('role', 'Admin')): ?>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash3">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/company.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($raw_material_items); ?></span>
                        </h5>
                        <h6>Total raw materials</h6>
                        <br>

                    </div>
                </div>
            </div>

            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash1">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/supplier.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalSuppliers); ?></span></h5>
                        <h6>Total suppliers</h6>
                        <br>

                    </div>
                    
                </div>
            </div>

            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash2">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/franchiser.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalFranchisers); ?></span>
                        </h5>
                        <h6>Total Franchisers</h6>
                        <br>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash1">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/sir.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"></span><?php echo e($totalInvoicesThisMonth); ?></h5>
                        <h6>Total Invoices - This Month</h6>


                    </div>
                    
                </div>
            </div>
        <?php endif; ?>
        <?php if (\Illuminate\Support\Facades\Blade::check('role', 'Manager')): ?>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash3">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/invoice.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"></span><?php echo e($totalInvoices); ?></h5>
                        <h6>Total Invoices</h6>
                        <br>

                    </div>
                    
                </div>
            </div>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash2">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/sir.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($store_issue_requisitions); ?></span></h5>
                        <h6>Total SIR</h6>
                        <br>

                    </div>
                    
                </div>
            </div>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash3">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/company.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($raw_material_items); ?></span>
                        </h5>
                        <h6>Total raw materials</h6>
                        <br>

                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-sm-6 col-12">
                <div class="dash-widget dash2">
                    <div class="dash-widgetimg">
                        <span><img src="assets/img/icons/product.svg" alt="img"></span>
                    </div>
                    <div class="dash-widgetcontent">
                        <h5><span class="counters"><?php echo e($totalproductsThisMonth); ?></span>
                        </h5>
                        <h6>Total products - This month</h6>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/aligkrwp/public_html/resources/views/admin/dashboard/index.blade.php ENDPATH**/ ?>