58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Reports;
|
|
|
|
use App\Services\SigdCrudService;
|
|
use App\Models\ReferenceEf;
|
|
use App\Models\ReferenceWs;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class WorksheetService extends SigdCrudService
|
|
{
|
|
public function __construct(ReferenceEf $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
public function getWorksheets($code = null)
|
|
{
|
|
if (is_null($code)) {
|
|
return [];
|
|
}
|
|
|
|
return ReferenceWs::rowActive()
|
|
->where('sector', $code)
|
|
->orderByRowNum()->isSub()
|
|
->get();
|
|
}
|
|
|
|
public function getWorksheet($code, $wsCode)
|
|
{
|
|
return ReferenceWs::where('sector', $code)->where('ws_code', $wsCode)->rowActive()->first();
|
|
}
|
|
|
|
public function getEmissionsData($modelClass, $inventoryYear, $activityYear, $wsCode = null)
|
|
{
|
|
// Check if the model class exists
|
|
if (!class_exists($modelClass)) {
|
|
return collect();
|
|
}
|
|
|
|
// Fetch emissions data
|
|
$query = $modelClass::where('inventory_year', $inventoryYear)
|
|
->where('activity_year', $activityYear)
|
|
->orderByRowNum()
|
|
->rowActive();
|
|
|
|
// Get the table name from the model
|
|
$table = (new $modelClass)->getTable();
|
|
|
|
// Check if the 'category' column exists in the table
|
|
if (Schema::hasColumn($table, 'category')) {
|
|
$query->where('category', $wsCode);
|
|
}
|
|
|
|
return $query->get();
|
|
}
|
|
}
|