added report data to api
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
namespace App\Transformers\Common;
 | 
			
		||||
 | 
			
		||||
use App\Models\Common\Report as Model;
 | 
			
		||||
use App\Utilities\Reports as Utility;
 | 
			
		||||
use League\Fractal\TransformerAbstract;
 | 
			
		||||
 | 
			
		||||
class Report extends TransformerAbstract
 | 
			
		||||
@@ -16,16 +17,34 @@ class Report extends TransformerAbstract
 | 
			
		||||
        return [
 | 
			
		||||
            'id' => $model->id,
 | 
			
		||||
            'company_id' => $model->company_id,
 | 
			
		||||
            'class' => $model->class,
 | 
			
		||||
            'name' => $model->name,
 | 
			
		||||
            'alias' => $model->alias,
 | 
			
		||||
            'description' => $model->description,
 | 
			
		||||
            'type' => $model->type,
 | 
			
		||||
            'group' => $model->group,
 | 
			
		||||
            'period' => $model->period,
 | 
			
		||||
            'basis' => $model->basis,
 | 
			
		||||
            'graph' => $model->graph,
 | 
			
		||||
            'settings' => $model->settings,
 | 
			
		||||
            'data' => $this->getReportData($model),
 | 
			
		||||
            'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
 | 
			
		||||
            'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function getReportData($model)
 | 
			
		||||
    {
 | 
			
		||||
        if (!Utility::canShow($model->class)) {
 | 
			
		||||
            return [];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $report = Utility::getClassInstance($model);
 | 
			
		||||
 | 
			
		||||
        if (empty($report)) {
 | 
			
		||||
            return [];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $unset_attributes = ['model', 'views', 'loaded', 'column_name_width', 'column_value_width'];
 | 
			
		||||
 | 
			
		||||
        foreach ($unset_attributes as $attribute) {
 | 
			
		||||
            unset($report->$attribute);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $report;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user