whereDate("test_date", ">=", get("d1")); $datas = $datas->whereDate("test_date", "<=", get("d2")); $get = true; } if(!getesit("rd1","")) { $datas = $datas->whereDate("request_date", ">=", get("rd1")); $datas = $datas->whereDate("request_date", "<=", get("rd2")); $get = true; } $datas = $datas->get(); $columns = [ 'test_laboratory', 'ndt_type', 'request_no', 'request_date', 'scope', 'contractor', 'project', 'design_area', 'line_specification', 'line_number', 'fluid_code', 'service_category', 'fluid_group', 'design_temperature_s', 'design_pressure_mpa', 'operating_temperature_s', 'operating_pressure_mpa', 'external_finish_type', 'iso_number', 'quantity_of_iso', 'iso_rev', 'spool_number', 'type_of_joint', 'no_of_the_joint_as_per_as_built_survey', 'type_of_welds', 'welding_date', 'wps_no', 'welding_method', 'welding_materials_1', 'welding_materials_1_lot_no', 'welding_materials_1_certificate_no', 'welding_materials_2', 'welding_materials_2_lot_no', 'welding_materials_2_certificate_no', 'welder_1', 'welder_2', 'certificate_no_1', 'wpq_report_1', 'certificate_no_2', 'wpq_report_2', 'member_no_1', 'material_no_1', 'ru_material_group_1', 'certificate_number_of_1', 'heat_number_1', 'nps_1', 'thickness_by_asme_1', 'outside_diameter_1', 'wall_thickness_1', 'pose_no_2', 'element_code_2', 'member_no_2', 'material_no_2', 'ru_material_group_2', 'certificate_number_of_2', 'heat_number_2', 'nps_2', 'thickness_by_asme_2', 'outside_diameter_2', 'wall_thickness_2', 'testing_date', 'report', 'result', 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', 'da', 'db', 'dc', 'ea', 'eb', 'ec', 'fa', 'fb', ]; $errorTypes = [ 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', 'da', 'db', 'dc', 'ea', 'eb', 'ec', 'fa', 'fb', ]; $refactoringDatas = []; $logTestTypes = log_test_types(); $testTypes = array_keys($logTestTypes); $testTypeTables = array_values($logTestTypes); $rejectedDate = [null, "0000-00-00", "", "1970-01-01"]; $allTestDatas = []; $k = 0; foreach($testTypeTables AS $testTypeTable) { $query = db($testTypeTable)->get(); $thisTestType = $testTypes[$k]; foreach($query AS $queryData) { $queryData = (Array) $queryData; $rowKey = $queryData['iso_number'] . $queryData['no_of_the_joint_as_per_as_built_survey']; $allTestDatas[$rowKey][$thisTestType]['control_standart'] = $queryData['control_standart']; if(array_key_exists("aa", $queryData)) { foreach($errorTypes AS $errorType) { $allTestDatas[$rowKey][$thisTestType][$errorType] = $queryData[$errorType]; } } } $k++; } foreach($datas AS $data) { foreach($testTypes AS $testType) { $requestDate = $testType . '_request_date'; $scope = $testType . '_scope'; $request_no = $testType . '_request_no'; $report = $testType . '_report'; $testing_date = $testType . '_test_date'; $result_no = $testType . '_result'; $test_laboratory = 'test_laboratory_' . $testType; if(!rejected_date($data->$requestDate)) { if($data->$testing_date == "") { if($data->$result_no == "") { $newData = (Array) $data; $newData['scope'] = $data->$scope; $newData['request_no'] = $data->$request_no; $newData['report'] = $data->$report; $newData['request_date'] = $data->$requestDate; $newData['testing_date'] = $data->$testing_date; $newData['ndt_type'] = strtoupper($testType); $newData['result'] = $data->$result_no; $rowKey = $data->iso_number . $data->no_of_the_joint_as_per_as_built_survey; $newData['control_standart'] = $allTestDatas[$rowKey][$testType]['control_standart'] ?? ''; $newData['test_laboratory'] = $data->$test_laboratory; $newData['test_type'] = $testType; $newData['iso_number'] = $data->iso_number; $newData['no_of_the_joint_as_per_as_built_survey'] = $data->no_of_the_joint_as_per_as_built_survey; $refactoringDatas[] = $newData; } } } } } /* $json = []; foreach($refactoringDatas AS $data) { $row = []; foreach($columns AS $column) { $row[$column] = ""; if(isset($data[$column])) { $row[$column] = $data[$column]; } elseif(array_key_exists($column, $errorTypes)) { $thisTestType = $data['test_type']; if(isset($allTestDatas[$data['iso_number'] . $data['no_of_the_joint_as_per_as_built_survey']][$thisTestType][$column])) { $row[$column] = $allTestDatas[$data['iso_number'] . $data['no_of_the_joint_as_per_as_built_survey']][$thisTestType][$column]; } } } $json[] = $row; } */ echo json_encode_tr($refactoringDatas); ?>