public function getDataSet($postData, $dcTable, $facility_id, $occur_date, $properties) { $eu_group_id = $postData['EnergyUnitGroup']; $record_freq = $postData['CodeReadingFrequency']; $phase_type = $postData['CodeFlowPhase']; $event_type = $postData['CodeEventType']; $alloc_type = array_key_exists('CodeAllocType', $postData) ? $postData['CodeAllocType'] : 0; $eu = EnergyUnit::getTableName(); $codeFlowPhase = CodeFlowPhase::getTableName(); $codeStatus = CodeStatus::getTableName(); $euPhaseConfig = EuPhaseConfig::getTableName(); $codeEventType = CodeEventType::getTableName(); $euWheres = ['FACILITY_ID' => $facility_id, 'FDC_DISPLAY' => 1]; if ($record_freq > 0) { $euWheres["{$eu}.DATA_FREQ"] = $record_freq; } if ($eu_group_id > 0) { $euWheres["{$eu}.EU_GROUP_ID"] = $eu_group_id; } // else $euWheres["$eu.EU_GROUP_ID"]= null; // \DB::enableQueryLog(); $dataSet = EnergyUnit::join($codeStatus, 'STATUS', '=', "{$codeStatus}.ID")->join($euPhaseConfig, function ($query) use($eu, $euPhaseConfig, $phase_type, $event_type) { $query->on("{$euPhaseConfig}.EU_ID", '=', "{$eu}.ID"); if ($phase_type > 0) { $query->where("{$euPhaseConfig}.FLOW_PHASE", '=', $phase_type); } if ($event_type > 0) { $query->where("{$euPhaseConfig}.EVENT_TYPE", '=', $event_type); } //TODO note chu y active co the se dung // $query->with('CodeFlowPhase'); // $query->select('FLOW_PHASE as EU_FLOW_PHASE'); })->join($codeFlowPhase, "{$euPhaseConfig}.FLOW_PHASE", '=', "{$codeFlowPhase}.ID")->join($codeEventType, "{$euPhaseConfig}.EVENT_TYPE", '=', "{$codeEventType}.ID")->where($euWheres)->whereDate('EFFECTIVE_DATE', '<=', $occur_date)->leftJoin($dcTable, function ($join) use($eu, $dcTable, $occur_date, $alloc_type, $euPhaseConfig) { //TODO add table name $join->on("{$eu}.ID", '=', "{$dcTable}.EU_ID")->on("{$dcTable}.FLOW_PHASE", '=', "{$euPhaseConfig}.FLOW_PHASE")->on("{$dcTable}.EVENT_TYPE", '=', "{$euPhaseConfig}.EVENT_TYPE")->where("{$dcTable}.OCCUR_DATE", '=', $occur_date); $energyUnitDataAlloc = EnergyUnitDataAlloc::getTableName(); $energyUnitCompDataAlloc = EnergyUnitCompDataAlloc::getTableName(); if ($alloc_type > 0 && ($dcTable == $energyUnitDataAlloc || $dcTable == $energyUnitCompDataAlloc)) { $join->where("{$dcTable}.ALLOC_TYPE", '=', $alloc_type); } })->select("{$eu}.name as {$dcTable}", "{$euPhaseConfig}.ID as DT_RowId", "{$codeFlowPhase}.name as PHASE_NAME", "{$codeEventType}.name as TYPE_NAME", "{$euPhaseConfig}.EVENT_TYPE as " . config("constants.eventType"), "{$eu}.ID as " . config("constants.euId"), "{$euPhaseConfig}.FLOW_PHASE as EU_FLOW_PHASE", "{$codeStatus}.NAME as STATUS_NAME", "{$codeFlowPhase}.CODE as PHASE_CODE", "{$codeEventType}.CODE as TYPE_CODE", "{$dcTable}.*")->orderBy($dcTable)->orderBy('EU_FLOW_PHASE')->get(); // \Log::info(\DB::getQueryLog()); return ['dataSet' => $dataSet]; }
public function getDefermentDetails($id) { $defermentDetail = DefermentDetail::getTableName(); // $defermentGroupEu =DefermentGroupEu::getTableName(); $energyUnit = EnergyUnit::getTableName(); $deferment = Deferment::getTableName(); $dataSet = Deferment::join($energyUnit, "{$deferment}.DEFER_TARGET", '=', "{$energyUnit}.ID")->leftJoin($defermentDetail, function ($join) use($defermentDetail, $deferment, $energyUnit) { $join->on("{$defermentDetail}.DEFERMENT_ID", '=', "{$deferment}.ID")->on("{$defermentDetail}.EU_ID", '=', "{$energyUnit}.ID"); })->where("{$deferment}.ID", '=', $id)->where("{$deferment}.DEFER_GROUP_TYPE", '=', 3)->select("{$energyUnit}.ID as ID", "{$energyUnit}.NAME as NAME", "{$energyUnit}.ID as DT_RowId", "{$deferment}.DEFER_GROUP_TYPE", "{$defermentDetail}.*")->get(); return $dataSet; }