12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Exports;
- use App\Models\Project;
- use App\Services\Project\ProjectGanttService;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\Exportable;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\ShouldAutoSize;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithMapping;
- use Maatwebsite\Excel\Events\AfterSheet;
- use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
- class ProjectGanttExport implements FromCollection, WithMapping, ShouldAutoSize
- {
- use Exportable;
- private static $index = 1;
- public function collection()
- {
- $project = Project::allowed(request()->project_id)->findOrFail(request()->project_id);
- $group = in_array(
- request()->get("group"),
- ['requirement_id','assign','task_type']
- ) ? request()->get("group") : "task_type";
- $header = ['id'=>'ID','parent'=> 0,'text'=>'Folder','start_date'=>'Start_Date','end_date'=>'End_Date','progress'=>'Progress','assign_to'=>'Assign_To'];
- $gantt = (new ProjectGanttService())->gantt($project, $group);
- array_unshift($gantt,$header);
- return new Collection($gantt);
- }
- public function map($project): array
- {
- $folder = '';
- if ($project['parent'] == 0){
- $folder = $project['text'];
- $displayId = $project['id'] =='ID'?'ID':'';
- $project['text'] = $project['text']=='Folder'?'Name':'';
- }else{
- $displayId = self::$index++;
- }
- return [
- $folder,
- $displayId,
- $project['text'],
- $project['parent'] != 0 ? ($project['progress'] * 100) . '%' : ($project['progress'] == 'Progress' ? 'Progress' : ''),
- $project['start_date'],
- $project['end_date'],
- $project['assign_to'],
- ];
- }
- }
|