0

I want to perform an export to totalize certain values.

My tables -> Services, Accounts, Profiles that are related to each other.

A Service has several accounts, an account has several profiles, a profile has a subscription

I need to generate 2 types of reports, in the first type of report I need to generate a table that separates the accounts by service, or that groups them in some way that allows to separate them. I have managed to generate the report but I can not separate the data by service.

My accountsExport Controller

public function view(): View
    {
        return view('admin.accounts.excel', [
            'services' => Service::all()->groupBy('1'),
            'accounts' => Account::where('status',1)->where('dateto', '<=' ,now()->addDays(4))->orderBy('service_id')->get(),

        ]);
    }

My Excel accountExport Blade

<div class="container" >
    <h1 >ACCOUNTS  REPORT</h1>

</div>

<table>
    <thead>
        <tr>
            <th>Service</th>
            <th>Email</th>
            <th>Password</th>
            <th>Country</th>
            <th>Expiration</th>
            <th>Last Days</th>
        </tr>
    </thead>
    <tbody>

        @foreach($accounts as $account)

            <tr>
                <td width="20">{{ $account->service->name }}</td>
                <td width="35">{{ $account->email }}</td>
                <td width="13">{{ $account->password }}</td>
                <td width="10">{{ $account->pais }}</td>
                <td width="20">{{ $account->dateto }}</td>
                <td width="10">{{ $account->last_days }}</td>
            </tr>
        @endforeach
    </tbody>
</table>

This gives me an excel file with this view

But what I want to get is this

I don't know how to make them separate and group them by Service

=====================================================================

My second Report

Each account has a certain number of profiles, but I need to total the profiles that are available per service.

I have managed to get the available profiles per account but what I really need is to total those numbers per service.

My serviceExport Controller

 public function view(): View
    {
        return view('admin.services.excel', [
            'services' => Service::all(),
            'servicesType' => Account::all(),


        ]);
    }

My Excel exportServices Blade

<h2>AVAILABEL PROFILES REPORT</h2>
@if($services->count() > 0)
<table id="example">
    <thead>
        <tr>
            <th>Service</th>
            <th>Email</th>
            <th>Password</th>
            <th>Total Profiles</th>
            <th>Profiles Used</th>
            <th>Available Profiles</th>
            <th>Date To</th>
        </tr>
    </thead>
    @foreach($servicesType as $account)
    <tbody>

        @php
        $used= $account->subscriptions->count();
        $total = $account->service->profiles;
        $available = $total - $used;
        @endphp

            <tr>
                <td width="20">{{ $account->service->name }}</td>
                <td width="35">{{ $account->email }}</td>
                <td width="18">{{ $account->password }}</td>
                <td width="18">{{ $total }}</td>
                <td width="18">{{ $used }}</td>
                <td width="18">{{ $available }}</td>
                <td width="20">{{ $account->dateto }}</td>
            </tr>
        </tbody>
        @endforeach
    </table>
    @endif

With this I generate the following file

But what I want to get is this

But what I want to get is this

I need to total the profiles available in the accounts and group them by service.

I am not able to count the available profiles in a grouped way but I can count them individually.

Thank you very much

1 Answer 1

0
you should your services each by column like

    
@foreach($accounts as $account)
<table>
    <thead>
        <tr>
            <th>Service {{$account->id}}</th>
            <th>Email</th>
            <th>Password</th>
            <th>Country</th>
            <th>Expiration</th>
            <th>Last Days</th>
        </tr>
    </thead>
    <tbody>

            <tr>
                <td width="20">{{ $account->service->name }}</td>
                <td width="35">{{ $account->email }}</td>
                <td width="13">{{ $account->password }}</td>
                <td width="10">{{ $account->pais }}</td>
                <td width="20">{{ $account->dateto }}</td>
                <td width="10">{{ $account->last_days }}</td>
            </tr>
    
    </tbody>
</table>

@endforeach
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.