%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/silvzytp/crm-ind-code/app/Exports/
Upload File :
Create Path :
Current File : /home/silvzytp/crm-ind-code/app/Exports/ManagerCallingExport.php

<?php

namespace App\Exports;

use App\Models\Colling;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;

class ManagerCallingExport implements FromCollection,WithHeadings
{

    protected $agent_name;
    protected $status;
    protected $sub_status;
    protected $potential;
    protected $start_date;
    protected $end_date;

    public function __construct($request)
    {
        $this->agent_name = $request->export_agent;
        $this->status     = $request->export_status;
        $this->sub_status = $request->export_sub_status;
        $this->potential  = $request->export_potential;
        $this->start_date = $request->start_date;
        $this->end_date   = $request->end_date;
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $exportData = [];
        $query = Colling::with('callingStatus','callingSubStatus','agent')->where('soft_data',0)
                ->whereIn('agent_id',Auth::user()->agents->pluck('id'))
                ->select('agent_id','file_name','serial','name','status','sub_status','potential','comment','follow_up1','follow_up2','follow_up3','comment_time','follow_up1_time','follow_up2_time','follow_up3_time','call_date','import_date');

        if (!empty($this->agent_name)) {
            $query->where('agent_id',$this->agent_name);
        }
        
        if (!empty($this->start_date) && !empty($this->end_date)) {
            $query->whereDate('call_date','>=',$this->start_date)
                ->whereDate('call_date','<=',$this->end_date);
        }

        if (!empty($this->status)) {
            $query->where('status',$this->status);
        }

        if (!empty($this->sub_status)) {
            $query->where('sub_status',$this->sub_status);
        }

        if (!empty($this->potential)) {
            $query->where('potential',$this->potential);
        }

        foreach ($query->get() as $key => $call) {
            $exportData[]=[
                'agent_id'        => $call->agent->name ?? 'N/A',
                'File Name'       => $call->file_name,
                'serial'          => $call->serial,
                'name'            => $call->name,
                'status'          => $call->callingStatus->name,
                'sub_status'      => $call->callingSubStatus->name,
                'potential'       => $call->potential ? POTENTIAL[$call->potential] : '',
                'comment'         => $call->comment,
                'follow_up1'      => $call->follow_up1,
                'follow_up2'      => $call->follow_up2,
                'follow_up3'      => $call->follow_up3,
                'comment_time'    => $call->comment_time,
                'follow_up1_time' => $call->follow_up1_time,
                'follow_up2_time' => $call->follow_up2_time,
                'follow_up3_time' => $call->follow_up3_time,
                'call_date'       => $call->call_date,
                'import_date'     => $call->import_date
            ];
        }

        $exportData[] = $query;
        return collect($exportData);
    }


    public function headings(): array
    {
        return [
            'Agent Name',
            'File Name',
            'Serial',
            'Name',
            'Status',
            'Sub Status',
            'Potential',
            'Comment',
            'Follow_up1',
            'Follow_up2',
            'Follow_up3',
            'Comment Time',
            'Follow_up1_time',
            'Follow_up2_time',
            'Follow_up3_time',
            'Call Date',
            'Import Date'
        ];
    }
}

Zerion Mini Shell 1.0