public function getInputDataSet($postData, $occur_date) { $phase_type = $postData['ExtensionPhaseType']; $value_type = $postData['ExtensionValueType']; $data_source = $postData['ExtensionDataSource']; $objs = $this->getPostObjects($postData); $objdata = array(); $objinfo = []; foreach ($objs as $obj) { if ($obj) { $ss = explode(":", $obj); $obj_id = $ss[1]; $src = $ss[0]; $obj_name = $ss[2]; $pre = $src; $pvalue = $src; $ele = $this->getElement($obj_name); $where = ["OCCUR_DATE" => $occur_date]; if ($src == "ENERGY_UNIT") { $pre = "EU"; $pvalue = $pre; $where['FLOW_PHASE'] = $phase_type; } else { if ($src == "FLOW") { $pvalue = "FL"; } } $where["{$pre}" . "_ID"] = $obj_id; $qlty_src_type = CodeQltySrcType::where('CODE', '=', $src)->first(); $mdl = $this->getObjectTable($src, $data_source); $objectData = $mdl::where($where)->select("OBS_TEMP", "OBS_PRESS", "{$pvalue}" . "_DATA_{$value_type} as OBJ_VALUE")->orderBy('OCCUR_DATE')->first(); $qltyData = QltyData::getTableName(); $qltyProductElementType = QltyProductElementType::getTableName(); $qltyDataDetail = QltyDataDetail::getTableName(); $qlty_datas = QltyData::join($qltyDataDetail, "{$qltyData}.ID", '=', "{$qltyDataDetail}.QLTY_DATA_ID")->join($qltyProductElementType, function ($query) use($qltyDataDetail, $phase_type, $qltyProductElementType) { $query->on("{$qltyDataDetail}.ELEMENT_TYPE", '=', "{$qltyProductElementType}.ID")->where("{$qltyProductElementType}.PRODUCT_TYPE", '=', $phase_type); })->whereHas('CodeQltySrcType', function ($query) use($src) { $query->where("CODE", $src)->skip(0)->take(1); })->where("{$qltyData}.SRC_ID", $obj_id)->where("{$qltyData}.PRODUCT_TYPE", $phase_type)->where('EFFECTIVE_DATE', '=', $occur_date)->select("{$qltyProductElementType}.NAME", "{$qltyDataDetail}.MOLE_FACTION")->get(); // foreach($workingDataSet as $objectData){ if ($objectData) { foreach ($qlty_datas as $qlty) { if (array_key_exists($qlty->NAME, $ele)) { $ele[$qlty->NAME] = $qlty->MOLE_FACTION ? $qlty->MOLE_FACTION : 0; } } $ele["Pressure"] = \Helper::getRoundValue($objectData->OBS_PRESS); $ele["Temperature"] = \Helper::getRoundValue($objectData->OBS_TEMP); $ele["Volume"] = \Helper::getRoundValue($objectData->OBJ_VALUE); $objdata["{$src}" . "_{$obj_id}"] = $ele; $objinfo[] = array("src" => $src, "pre" => $pre, "obj_id" => $obj_id); } // } } } return ['data' => $objdata, 'info' => $objinfo]; }
public function getDataSet($postData, $dcTable, $facility_id, $occur_date, $properties) { $mdlName = $postData[config("constants.tabTable")]; $mdl = "App\\Models\\{$mdlName}"; $src_type_id = $postData['CodeQltySrcType']; $date_end = $postData['date_end']; $date_end = \Helper::parseDate($date_end); $filterBy = $postData['cboFilterBy']; $extraDataSet = []; $dataSet = null; $codeQltySrcType = CodeQltySrcType::getTableName(); // $qltData = $mdl::getTableName(); $uoms = $properties['uoms']; $sourceTypekey = array_search('CodeQltySrcType', array_column($uoms, 'id')); $sourceTypes = $uoms[$sourceTypekey]['data']; $objectType = null; $src_type_ids = $src_type_id == 0 ? [1, 2, 3, 4, 5, 6] : [$src_type_id]; $query = null; // \DB::enableQueryLog(); foreach ($src_type_ids as $srcTypeId) { $where = ['SRC_TYPE' => $srcTypeId]; switch ($srcTypeId) { case 1: case 2: case 3: case 4: $objectType = $sourceTypes->find($srcTypeId); $objectType = $objectType->CODE; $cquery = $mdl::join($objectType, function ($query) use($objectType, $facility_id, $dcTable) { $query->on("{$objectType}.ID", '=', "{$dcTable}.SRC_ID")->where("{$objectType}.FACILITY_ID", '=', $facility_id); })->where($where)->whereDate("{$dcTable}.{$filterBy}", '>=', $occur_date)->whereDate("{$dcTable}.{$filterBy}", '<=', $date_end)->select("{$dcTable}.ID as {$dcTable}", "{$dcTable}.ID as DT_RowId", "{$dcTable}.ID", "{$dcTable}.*")->orderBy($dcTable); // ->get(); $query = $query == null ? $cquery : $query->union($cquery); break; case 5: $objectType = $sourceTypes->find($srcTypeId); $objectType = $objectType->CODE; $storage = Storage::getTableName(); $pdVoyageDetail = PdVoyageDetail::getTableName(); $pdVoyage = PdVoyage::getTableName(); $cquery = $mdl::join($pdVoyageDetail, "{$dcTable}.SRC_ID", '=', "{$pdVoyageDetail}.ID")->join($pdVoyage, "{$pdVoyageDetail}.VOYAGE_ID", '=', "{$pdVoyage}.ID")->join($storage, function ($query) use($storage, $facility_id, $pdVoyage) { $query->on("{$storage}.ID", '=', "{$pdVoyage}.STORAGE_ID")->where("{$storage}.FACILITY_ID", '=', $facility_id); })->where($where)->whereDate($filterBy, '>=', $occur_date)->whereDate($filterBy, '<=', $date_end)->select("{$dcTable}.ID as {$dcTable}", "{$dcTable}.ID as DT_RowId", "{$dcTable}.ID", "{$dcTable}.*")->orderBy($dcTable); // ->get(); $query = $query == null ? $cquery : $query->union($cquery); break; case 6: $objectType = $sourceTypes->find($srcTypeId); $objectType = $objectType->CODE; $cquery = $mdl::where($where)->whereDate($filterBy, '>=', $occur_date)->whereDate($filterBy, '<=', $date_end)->select("{$dcTable}.ID as {$dcTable}", "{$dcTable}.ID as DT_RowId", "{$dcTable}.ID", "{$dcTable}.*")->orderBy($dcTable); // ->get(); $query = $query == null ? $cquery : $query->union($cquery); break; } } if ($query != null) { $dataSet = $query->get(); } // \Log::info(\DB::getQueryLog()); $sourceColumn = 'SRC_TYPE'; if ($dataSet && $dataSet->count() > 0) { if ($src_type_id > 0) { $srcTypeData = $this->getExtraDatasetBy($objectType, $facility_id); if ($srcTypeData) { $extraDataSet[$sourceColumn] = []; $extraDataSet[$sourceColumn][$src_type_id] = $srcTypeData; } } else { // \DB::enableQueryLog(); $bySrcTypes = $dataSet->groupBy('SRC_ID'); // \Log::info(\DB::getQueryLog()); if ($bySrcTypes) { $extraDataSet[$sourceColumn] = []; foreach ($bySrcTypes as $key => $srcType) { $srcTypeID = $srcType[0]->SRC_TYPE; $table = $sourceTypes->find($srcTypeID); $table = $table->CODE; $srcTypeData = $this->getExtraDatasetBy($table, $facility_id); if ($srcTypeData) { $extraDataSet[$sourceColumn][$srcTypeID] = $srcTypeData; } } } } } return ['dataSet' => $dataSet, 'extraDataSet' => $extraDataSet]; }
public function getUoms($properties = null, $facility_id, $dcTable = null, $locked = false) { $uoms = []; $model = null; $withs = []; $i = 0; $selectData = false; $rs = []; foreach ($properties as $property) { $columnName = is_array($property) && array_key_exists('data', $property) ? $property['data'] : $property->data; switch ($columnName) { case 'PRESS_UOM': $withs[] = 'CodePressUom'; $uoms[] = ['id' => 'CodePressUom', 'targets' => $i, 'COLUMN_NAME' => 'PRESS_UOM']; break; case 'TEMP_UOM': $withs[] = 'CodeTempUom'; $uoms[] = ['id' => 'CodeTempUom', 'targets' => $i, 'COLUMN_NAME' => 'TEMP_UOM']; break; case 'FL_POWR_UOM': case 'EU_POWR_UOM': $withs[] = 'CodePowerUom'; $uoms[] = ['id' => 'CodePowerUom', 'targets' => $i, 'COLUMN_NAME' => 'FL_POWR_UOM']; break; case 'FL_ENGY_UOM': case 'EU_ENGY_UOM': $withs[] = 'CodeEnergyUom'; $uoms[] = ['id' => 'CodeEnergyUom', 'targets' => $i, 'COLUMN_NAME' => 'FL_ENGY_UOM']; break; case 'FL_MASS_UOM': case 'EU_MASS_UOM': $withs[] = 'CodeMassUom'; $uoms[] = ['id' => 'CodeMassUom', 'targets' => $i, 'COLUMN_NAME' => 'FL_MASS_UOM']; break; case 'VOL_UOM': case 'FL_VOL_UOM': case 'EU_VOL_UOM': $withs[] = 'CodeVolUom'; $uoms[] = ['id' => 'CodeVolUom', 'targets' => $i, 'COLUMN_NAME' => 'FL_VOL_UOM']; break; case 'EU_STATUS': $selectData = ['id' => 'EuStatus', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = collect([(object) ['ID' => -1, 'NAME' => '(Auto)'], (object) ['ID' => 1, 'NAME' => 'Online'], (object) ['ID' => 0, 'NAME' => 'Offline']]); $rs[] = $selectData; break; case 'ALLOC_TYPE': $selectData = ['id' => 'CodeAllocType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeAllocType::all(); $rs[] = $selectData; break; case 'TEST_METHOD': $selectData = ['id' => 'CodeTestingMethod', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeTestingMethod::all(); $rs[] = $selectData; break; case 'TEST_USAGE': $selectData = ['id' => 'CodeTestingUsage', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeTestingUsage::all(); $rs[] = $selectData; break; case 'EVENT_TYPE': $selectData = ['id' => 'CodeEventType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeEventType::all(); $rs[] = $selectData; break; case 'SRC_TYPE': $selectData = ['id' => 'CodeQltySrcType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeQltySrcType::all(); $rs[] = $selectData; break; case 'PRODUCT_TYPE': $selectData = ['id' => 'CodeProductType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeProductType::all(); $rs[] = $selectData; break; case 'DEFER_REASON': $selectData = ['id' => 'CodeDeferReason', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeDeferReason::all(); $rs[] = $selectData; break; case 'DEFER_STATUS': $selectData = ['id' => 'CodeDeferStatus', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeDeferStatus::all(); $rs[] = $selectData; break; case 'CODE1': $selectData = ['id' => 'CodeDeferCode1', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeDeferCode1::all(); $rs[] = $selectData; break; case 'DEFER_CATEGORY': $selectData = ['id' => 'CodeDeferCategory', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeDeferCategory::all(); $rs[] = $selectData; break; case 'DEFER_GROUP_TYPE': $selectData = ['id' => 'CodeDeferGroupType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeDeferGroupType::all(); $rs[] = $selectData; break; case 'TICKET_TYPE': $selectData = ['id' => 'CodeTicketType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeTicketType::all(); $rs[] = $selectData; break; case 'TARGET_TANK': $selectData = ['id' => 'Tank', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = Tank::where('FACILITY_ID', $facility_id)->get(); $rs[] = $selectData; break; case 'CARRIER_ID': case 'PD_TRANSIT_CARRIER_ID': case 'CONNECTING_CARRIER': if ($dcTable == \App\Models\PdCargoNomination::getTableName() && !$locked) { break; } $selectData = ['id' => 'PdTransitCarrier', 'targets' => $i, 'COLUMN_NAME' => $columnName]; if ($dcTable == \App\Models\RunTicketFdcValue::getTableName() || $dcTable == \App\Models\RunTicketValue::getTableName()) { $selectData['data'] = PdTransitCarrier::where('TRANSIT_TYPE', 1)->get(); } else { $selectData['data'] = PdTransitCarrier::all(); } $rs[] = $selectData; break; case 'BA_ID': if ($dcTable != Personnel::getTableName()) { $selectData = ['id' => 'BaAddress', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = BaAddress::all(); $rs[] = $selectData; } break; case 'SEVERITY_ID': $selectData = ['id' => 'CodeSafetySeverity', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeSafetySeverity::where('ACTIVE', 1)->orderBy('ORDER')->orderBy('ID')->get(); $rs[] = $selectData; break; case 'STATUS': $selectData = ['id' => 'CodeCommentStatus', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeCommentStatus::where('ACTIVE', 1)->orderBy('ORDER')->orderBy('ID')->get(); $rs[] = $selectData; break; case 'OFFLINE_REASON_CODE': $selectData = ['id' => 'CodeEqpOfflineReason', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeEqpOfflineReason::where('ACTIVE', 1)->orderBy('ORDER')->orderBy('ID')->get(); $rs[] = $selectData; break; case 'EQP_FUEL_CONS_TYPE': $selectData = ['id' => 'CodeEqpFuelConsType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeEqpFuelConsType::where('ACTIVE', 1)->orderBy('ORDER')->orderBy('ID')->get(); $rs[] = $selectData; break; case 'EQP_GHG_REL_TYPE': $selectData = ['id' => 'CodeEqpGhgRelType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeEqpGhgRelType::where('ACTIVE', 1)->orderBy('ORDER')->orderBy('ID')->get(); $rs[] = $selectData; break; case 'EQP_GHG_UOM': case 'EQP_CONS_UOM': $selectData = ['id' => 'CodeVolUom', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeVolUom::all(); $rs[] = $selectData; break; case 'TYPE': $selectData = ['id' => 'CodePersonnelType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodePersonnelType::all(); $rs[] = $selectData; break; case 'TITLE': $selectData = ['id' => 'CodePersonnelTitle', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodePersonnelTitle::all(); $rs[] = $selectData; break; case 'SYSTEM_ID': $selectData = ['id' => 'IntSystem', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = IntSystem::all(); $rs[] = $selectData; break; case 'FREQUENCY': $selectData = ['id' => 'CodeReadingFrequency', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeReadingFrequency::all(); $rs[] = $selectData; break; case 'ALLOW_OVERRIDE': $selectData = ['id' => 'CodeBoolean', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeBoolean::all(); $rs[] = $selectData; break; case 'FLOW_PHASE': $selectData = ['id' => 'CodeFlowPhase', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = CodeFlowPhase::all(); $rs[] = $selectData; break; case 'REQUEST_UOM': case 'NOMINATION_UOM': case 'REQUEST_QTY_UOM': case 'SCHEDULE_UOM': case 'ATTRIBUTE_UOM': case 'LOAD_UOM': case 'QTY_UOM': case 'ITEM_UOM': $selectData = ['id' => 'PdCodeMeasUom', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeMeasUom::all(); $rs[] = $selectData; break; case 'PRIORITY': $selectData = ['id' => 'PdCodeCargoPriority', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeCargoPriority::all(); $rs[] = $selectData; break; case 'QUANTITY_TYPE': $selectData = ['id' => 'PdCodeCargoQtyType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeCargoQtyType::all(); $rs[] = $selectData; break; case 'LIFTING_ACCT': case 'LIFTING_ACCOUNT': $selectData = ['id' => 'PdLiftingAccount', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdLiftingAccount::all(); $rs[] = $selectData; break; case 'CONTRACT_ID': $selectData = ['id' => 'PdContract', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdContract::all(); $rs[] = $selectData; break; case 'STORAGE_ID': $selectData = ['id' => 'Storage', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\Storage::where('FACILITY_ID', $facility_id)->get(); $rs[] = $selectData; break; case 'REQUEST_TOLERANCE': $selectData = ['id' => 'PdCodeQtyAdj', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeQtyAdj::all(); $rs[] = $selectData; break; case 'ADJUSTABLE_TIME': case 'NOMINATION_ADJ_TIME': $selectData = ['id' => 'PdCodeTimeAdj', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeTimeAdj::all(); $rs[] = $selectData; break; case 'INCOTERM': $selectData = ['id' => 'PdCodeIncoterm', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeIncoterm::all(); $rs[] = $selectData; break; case 'TRANSIT_TYPE': $selectData = ['id' => 'PdCodeTransitType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeTransitType::all(); $rs[] = $selectData; break; /* case 'ACTIVITY_NAME' : $selectData = ['id'=>'ID','targets'=>$i,'COLUMN_NAME'=>'NAME']; $sql = ""; $sql .= " SELECT ID, NAME FROM pd_code_load_activity a where exists (select 1 from PD_CARGO_LOAD b join TERMINAL_TIMESHEET_DATA c ON ( b.ID = c.PARENT_ID AND c.IS_LOAD = 1 ) where c.ACTIVITY_ID = a.ID)"; $sql .= " union all"; $sql .= " SELECT ID, NAME FROM pd_code_load_activity a where exists (select 1 from PD_CARGO_UNLOAD b join TERMINAL_TIMESHEET_DATA c ON ( b.ID = c.PARENT_ID AND c.IS_LOAD = 1 ) where c.ACTIVITY_ID = a.ID)"; $tmp = \DB::select($sql); $selectData['data'] = $tmp; $rs[] = $selectData; break; */ /* case 'ACTIVITY_NAME' : $selectData = ['id'=>'ID','targets'=>$i,'COLUMN_NAME'=>'NAME']; $sql = ""; $sql .= " SELECT ID, NAME FROM pd_code_load_activity a where exists (select 1 from PD_CARGO_LOAD b join TERMINAL_TIMESHEET_DATA c ON ( b.ID = c.PARENT_ID AND c.IS_LOAD = 1 ) where c.ACTIVITY_ID = a.ID)"; $sql .= " union all"; $sql .= " SELECT ID, NAME FROM pd_code_load_activity a where exists (select 1 from PD_CARGO_UNLOAD b join TERMINAL_TIMESHEET_DATA c ON ( b.ID = c.PARENT_ID AND c.IS_LOAD = 1 ) where c.ACTIVITY_ID = a.ID)"; $tmp = \DB::select($sql); $selectData['data'] = $tmp; $rs[] = $selectData; break; */ case 'CARGO_ID': $selectData = ['id' => 'PdCargo', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCargo::all(); $rs[] = $selectData; break; case 'BERTH_ID': $selectData = ['id' => 'PdBerth', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdBerth::all(); $rs[] = $selectData; break; case 'CARGO_STATUS': $selectData = ['id' => 'PdCodeCargoStatus', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeCargoStatus::all(); $rs[] = $selectData; break; case 'CONTRACT_TYPE': case 'CONTACT_TYPE': $selectData = ['id' => 'PdCodeContractType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeContractType::all(); $rs[] = $selectData; break; case 'CONTRACT_PERIOD': $selectData = ['id' => 'PdCodeContractPeriod', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeContractPeriod::all(); $rs[] = $selectData; break; case 'CONTRACT_EXPENDITURE': $selectData = ['id' => 'PdContractExpenditure', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdContractExpenditure::all(); $rs[] = $selectData; break; case 'CONTRACT_TEMPLATE': $selectData = ['id' => 'PdContractTemplate', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdContractTemplate::all(); $rs[] = $selectData; break; case 'DEMURRAGE_EBO': $selectData = ['id' => 'PdCodeDemurrageEbo', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeDemurrageEbo::all(); $rs[] = $selectData; break; case 'SURVEYOR_BA_ID': $selectData = ['id' => 'BaAddress', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\BaAddress::where('SOURCE', 15)->get(); $rs[] = $selectData; break; case 'WITNESS_BA_ID1': case 'WITNESS_BA_ID2': $selectData = ['id' => 'BaAddress', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\BaAddress::where('SOURCE', 4)->get(); $rs[] = $selectData; break; case 'ACTIVITY_ID': case 'ACTIVITY_NAME': $selectData = ['id' => 'PdCodeLoadActivity', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeLoadActivity::all(); $rs[] = $selectData; break; case 'VOYAGE_ID': $selectData = ['id' => 'PdVoyage', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdVoyage::all(); $rs[] = $selectData; break; case 'DEPART_PORT': case 'NEXT_DESTINATION_PORT': case 'PORT_ID': case 'ULLAGE_PORT': case 'ORIGIN_PORT': case 'DESTINATION_PORT': $selectData = ['id' => 'PdPort', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdPort::all(); $rs[] = $selectData; break; case 'FLOW_ID': $selectData = ['id' => 'Flow', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\Flow::where("FACILITY_ID", '=', $facility_id)->get(); $rs[] = $selectData; break; case 'MEASURED_ITEM': $selectData = ['id' => 'PdCodeMeasItem', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeMeasItem::all(); $rs[] = $selectData; break; case 'FORMULA_ID': $selectData = ['id' => 'Formula', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\Formula::where("GROUP_ID", '=', 7)->get(); $rs[] = $selectData; break; case 'PROGRAM_TYPE': $selectData = ['id' => 'PdCodeProgramType', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeProgramType::all(); $rs[] = $selectData; break; case 'RUN_FREQUENCY': $selectData = ['id' => 'PdCodeRunFrequency', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeRunFrequency::all(); $rs[] = $selectData; break; case 'ADJUST_CODE': $selectData = ['id' => 'PdCodeLiftAcctAdj', 'targets' => $i, 'COLUMN_NAME' => $columnName]; $selectData['data'] = \App\Models\PdCodeLiftAcctAdj::all(); $rs[] = $selectData; break; } $i++; } if (count($withs) > 0) { $model = StandardUom::with($withs)->where('ID', $facility_id)->first(); if ($model == null) { $model = Facility::with($withs)->where('ID', $facility_id)->first(); } } // \DB::enableQueryLog(); if ($model != null) { foreach ($uoms as $key => $uom) { $uom['data'] = $model->{$uom}['id']; $uoms[$key] = $uom; $rs[] = $uom; } } return $rs; // \Log::info(\DB::getQueryLog()); }
public static function calculateBg($flow_phase, $T_obs, $P_obs, $API_obs, $occur_date, $object_id, $object_type_code) { $_Bg = null; set_error_handler("evalErrorHandler"); if ($flow_phase == 1) { try { if ($T_obs && $P_obs && $API_obs) { $_Bg = self::calculateCrudeOil($T_obs, $P_obs, $API_obs); } } catch (Exception $e) { \Log::info($e->getTraceAsString()); } } else { if ($flow_phase == 2 || $flow_phase == 21) { $cqst = CodeQltySrcType::getTableName(); $qdata = QltyData::getTableName(); $row = QltyData::getQualityRow($object_id, $object_type_code, $occur_date); /* $row= QltyData::with(['CodeQltySrcType' => function ($query) use ($object_type_code) { $query->where('CODE', '=', $object_type_code); }]) ->where('SRC_ID',$object_id) ->whereDate("$qdata.EFFECTIVE_DATE", '<=', $occur_date) ->select("$qdata.ID") ->orderBy("$qdata.EFFECTIVE_DATE",'desc') ->first(); */ //Find composition %Mol // $sSQL="select a.ID from qlty_data a, code_qlty_src_type b where a.SRC_ID='$object_id' and a.SRC_TYPE=b.ID and b.CODE='$object_type_code' and a.EFFECTIVE_DATE<=STR_TO_DATE('$occur_date', '%m/%d/%Y') order by a.EFFECTIVE_DATE desc limit 1"; if ($row) { $dataID = $row->ID; // \DB::enableQueryLog(); $querys = ['C1' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C1'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C2'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C3' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C3'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C4I' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'IC4'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C4N' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'NC4'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C5I' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'IC5'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C5N' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'NC5'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C6' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C6'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'C7' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C7+'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'H2S' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'H2S'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'CO2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'CO2'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'N2' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'N2'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(MOLE_FACTION)")), 'M_C7' => QltyProductElementType::where('CODE', 'C7+')->select(\DB::raw("max(MOL_WEIGHT)")), 'G_C7' => QltyDataDetail::whereHas('QltyProductElementType', function ($query) { $query->where("CODE", 'C7+'); })->where('QLTY_DATA_ID', $dataID)->select(\DB::raw("max(GAMMA_C7)"))]; $qr = \DB::table(null); foreach ($querys as $key => $query) { $qr = $qr->selectSub($query->getQuery(), $key); } $qdltDatas = $qr->first(); // \Log::info("qdltDatas C1 ".$qdltDatas->C1); // \Log::info(\DB::getQueryLog()); if ($qdltDatas) { $MolWt_C7 = $qdltDatas->M_C7; $gamma_C7 = $qdltDatas->G_C7; $M_C1 = $qdltDatas->C1; $M_C2 = $qdltDatas->C2; $M_C3 = $qdltDatas->C3; $M_C4n = $qdltDatas->C4N; $M_C4i = $qdltDatas->C4I; $M_C5n = $qdltDatas->C5N; $M_C5i = $qdltDatas->C5I; $M_C6n = $qdltDatas->C6; $M_C7 = $qdltDatas->C7; $M_H2S = $qdltDatas->H2S; $M_CO2 = $qdltDatas->CO2; $M_N2 = $qdltDatas->N2; if ($T_obs && $P_obs) { try { $_Bg = self::calculateGas($T_obs, $P_obs, $MolWt_C7, $gamma_C7, $M_C1, $M_C2, $M_C3, $M_C4n, $M_C4i, $M_C5n, $M_C5i, $M_C6n, $M_C7, $M_H2S, $M_CO2, $M_N2); } catch (Exception $e) { \Log::info($e->getTraceAsString()); } } } } } } restore_error_handler(); return $_Bg; }