model = $model; } public function save($code, $inventoryYear) { try { $dataBatch = []; $ws = $this->getWs($code); $years = activityYearRange($inventoryYear); if ($ws && class_basename($ws->model) == 'Waste4D1a') { foreach ($years as $year) { $dataBatch = array_merge($dataBatch, $this->calcAndSave($inventoryYear, $year, $ws)); } } else { throw new \Exception("Forbidden"); } return $dataBatch; } catch (\Exception $e) { throw $e; } } public function calcAndSave($inventoryYear, $activityYear, $ws) { $dataForms = []; $sector = $this->sectorCode; $code = $this->formCode; $wsCode = $ws->ws_code; try { // ambil data aktivitas $population = ActivityFormDetail::getValue($inventoryYear, $activityYear, $sector, $code, 'jumlah_penduduk'); $ef_bod = ReferenceEf::getValue('jumlah_penduduk', 'BOD'); $ef_cf = ReferenceEf::getValue('jumlah_penduduk', 'CF'); $tow = $population * $ef_bod * $ef_cf; $no = 1; $dataForm = [ 'inventory_year' => $inventoryYear, 'activity_year' => $activityYear, 'category' => $wsCode, 'population' => $population, 'ef_bod' => $ef_bod, 'ef_correction_factor' => $ef_cf, 'tow' => $tow, 'row_num' => $no++, ]; $this->createOrUpdate([ 'inventory_year' => $inventoryYear, 'activity_year' => $activityYear, 'category' => $wsCode, 'row_status' => 1, ], $dataForm); $dataForms[] = $dataForm; return $dataForms; } catch (\Exception $e) { throw $e; } } }