public function actionExport($id)
 {
     $filepath = dirname(__FILE__) . '/../runtime/result.docx';
     $template_filepath = dirname(__FILE__) . '/../runtime/templates/Template.docx';
     if (file_exists($template_filepath)) {
         $resource = Resource::findOne($id);
         $filename = $resource->name . '.docx';
         $coordinates = json_decode($resource->coordinates);
         $owner = PersonalData::findOne($resource->owner_data_id);
         $owner_name = $owner->last_name . ' ' . $owner->first_name . ' ' . $owner->middle_name;
         $resource_class = ResourceClass::findOne($resource->class_id)->name;
         $parameters = Parameter::find()->where(['resource_id' => $id])->all();
         $attributes = [];
         foreach ($parameters as $parameter) {
             $parameter_name = ResourceAttribute::findOne($parameter->attribute_id);
             $attributes[$parameter_name->name] = $parameter->value;
         }
         $linear_size = $attributes['length'];
         if ($attributes['width']) {
             $linear_size .= ':' . $attributes['width'];
         }
         if ($attributes['height']) {
             $linear_size .= ':' . $attributes['height'];
         }
         \PhpOffice\PhpWord\Autoloader::register();
         $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template_filepath);
         // Template processing
         $templateProcessor->setValue('name', htmlspecialchars($resource->name, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('class', htmlspecialchars($resource_class, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('subclass', htmlspecialchars($subclass, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('owner', htmlspecialchars($owner_name, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('linear_size', htmlspecialchars($linear_size, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('area', htmlspecialchars($attributes['square'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('weight', htmlspecialchars($attributes['weight'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('perimeter', htmlspecialchars($attributes['perimeter'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('volume', htmlspecialchars($attributes['volume'], ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('reason', htmlspecialchars($reason, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar_address', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registration_number', htmlspecialchars($registration_number, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registration_date', htmlspecialchars($creation_date, ENT_COMPAT, 'UTF-8'));
         $templateProcessor->setValue('registrar_shortname', htmlspecialchars($registrar_short_name, ENT_COMPAT, 'UTF-8'));
         for ($i = 1; $i <= 20; $i++) {
             $lat = "";
             $lng = "";
             if (count($coordinates) >= $i) {
                 $lat = $coordinates[$i - 1][0];
                 $lng = $coordinates[$i - 1][1];
             }
             $templateProcessor->setValue('lat#' . $i, htmlspecialchars($lat, ENT_COMPAT, 'UTF-8'));
             $templateProcessor->setValue('lng#' . $i, htmlspecialchars($lng, ENT_COMPAT, 'UTF-8'));
         }
         // Saving the document as OOXML file...
         $templateProcessor->saveAs($filepath);
         if (file_exists($filepath)) {
             return \Yii::$app->response->sendFile($filepath, $filename, ['inline' => false])->send();
         }
     }
 }
 public function actionAdduser()
 {
     /*       echo \Yii::$app->basePath;
             echo \Yii::$app->session->get('role');
             exit('1');*/
     if (!($post = \Yii::$app->getRequest()->getBodyParams())) {
         throw new \yii\web\HttpException(400, 'Дані не отримані');
     }
     $userModel = new User();
     if ($userModel->findByUsername($post['username'])) {
         throw new \yii\web\HttpException(400, 'Користувач з таким логіном уже існує');
     }
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         $personalDataModel = new PersonalData();
         $personalDataModel->last_name = $post['last_name'];
         $personalDataModel->first_name = $post['first_name'];
         $personalDataModel->middle_name = $post['middle_name'];
         $personalDataModel->passport_series = $post['passport_series'];
         $personalDataModel->passport_number = $post['passport_number'];
         $personalDataModel->address = $post['address'];
         if (!$personalDataModel->save()) {
             foreach ($personalDataModel->errors as $key) {
                 $errorMessage .= $key[0];
             }
             throw new \yii\web\HttpException(422, $errorMessage);
         }
         $userModel = new User();
         $userModel->username = $post['username'];
         $password = $post['password'];
         $validator = new \yii\validators\StringValidator(['min' => 3, 'max' => 12, 'tooShort' => 'Пароль повинен містити мінімум {min, number} символи', 'tooLong' => 'Пароль повинен містити не більше {max, number} символів']);
         if (!$validator->validate($password, $error)) {
             throw new \yii\web\HttpException(422, $error);
         }
         $userModel->setPassword($post['password']);
         $userModel->email = $post['email'];
         $userModel->role_id = 2;
         $userModel->user_data_id = $personalDataModel->personal_data_id;
         $userModel->generateAuthKey();
         if (!$userModel->save()) {
             foreach ($userModel->errors as $key) {
                 $errorMessage .= $key[0];
             }
             throw new \yii\web\HttpException(422, $errorMessage);
         }
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         throw new \yii\web\HttpException(422, $errorMessage . $error);
         return $errorMessage . $error;
     }
     exit('end');
 }
 public function update(Request $request, $id)
 {
     $data = $request->all();
     $data['id_record'] = $id;
     $datafile = FileData::where('id_record', $id)->get();
     for ($i = 1; $i <= 9; $i++) {
         // Upload new image
         if ($request->hasFile('input' . $i)) {
             $foto = $datafile[$i - 1]->url;
             $image = UploadX::uploadFile($request->file('input' . $i), 'pictures', $i . time());
             $data['input' . $i] = $image['url'];
         } else {
             $foto = $datafile[$i - 1]->url;
             $data['input' . $i] = $foto;
         }
     }
     for ($i = 7; $i <= 8; $i++) {
         $key = 'input' . $i;
         if ($request->hasFile($key)) {
             // Create a instance for imagick with the url of PDF
             $im = new Imagick();
             $im->setResolution(144, 144);
             $im->readImage($data[$key] . '[0]');
             $im->setImageFormat('png');
             // Set the url of the image converted
             $url = 'pictures/' . $i . time() . '.png';
             // Put the image in the public folder
             file_put_contents($url, $im);
             // Remove the PDF uploaded
             UploadX::deleteFile($data[$key]);
             // Set the new url for the image
             $data[$key] = $url;
         }
     }
     //llenamos los campos vacios
     $data = array_map(function ($item) {
         return $item == '' ? '-----' : $item;
     }, $data);
     //Guardo en el repo
     $data['name'] = \Auth::user()->name;
     $data['job'] = \Auth::user()->job;
     $ballot_data = $this->repo->findOrFail($id);
     $ballot_data = $this->repo->update($ballot_data, $data);
     $ballot_data->id_user = \Auth::id();
     $ballot_data->puesto = $data['puesto_empresa'];
     $ballot_data->empresa = $data['nombre_empresa'];
     $ballot_data->nombre = $data['dp1'] . ' ' . $data['dp2'];
     $ballot_data->observacion = $data['observacion'];
     $ballot_data->save();
     //Guardamos en la tabla datos personales
     $dataPersonal = PersonalData::where('id_record', $id)->first();
     $dataPersonal = $this->personalDataRepo->update($dataPersonal, $data);
     $dataPersonal->dp1 = $data['dp1'];
     $dataPersonal->dp2 = $data['dp2'];
     $dataPersonal->dp3 = $data['dp3'];
     $dataPersonal->dp4 = $data['dp4'];
     $dataPersonal->dp5 = $data['dp5'];
     $dataPersonal->dp6 = $data['dp6'];
     $dataPersonal->dp7 = $data['dp7'];
     $dataPersonal->dp8 = $data['dp8'];
     $dataPersonal->dp9 = $data['dp9'];
     $dataPersonal->dp10 = $data['dp10'];
     $dataPersonal->dp11 = $data['dp11'];
     $dataPersonal->dp12 = $data['dp12'];
     $dataPersonal->dp13 = $data['dp13'];
     $dataPersonal->dp14 = $data['dp14'];
     $dataPersonal->dp15 = $data['dp15'];
     $dataPersonal->id_record = $id;
     $dataPersonal->save();
     //Guardamos en la tabla archivos
     $datafile = FileData::where('id_record', $id)->get();
     $i = 1;
     $indice = 0;
     while ($i <= 9) {
         $url = $data['input' . $i];
         if ($datafile[$indice]->url != $url && $url != '-----') {
             UploadX::deleteFile($datafile[$indice]->url);
             $datafile[$indice]->url = $data['input' . $i];
         }
         $datafile[$indice]->id_record = $id;
         $datafile[$indice]->save();
         $i++;
         $indice++;
     }
     //Guardar en la tabla datos familiares
     //Guardar la informacion sobre el padre
     $dataPadre = FamilyData::whereRaw('tipo = ? and id_record = ?', ['padre', $id])->first();
     $dataPadre = $this->familyDataRepo->update($dataPadre, $data);
     $dataPadre->tipo = 'padre';
     $dataPadre->nombre = $data['df1'];
     $dataPadre->edad = $data['df2'];
     $dataPadre->originario = $data['df3'];
     $dataPadre->ingresos = $data['df4'];
     $dataPadre->profecion = $data['df5'];
     $dataPadre->telefono = $data['df6'];
     $dataPadre->direccion = $data['df7'];
     $dataPadre->relacion = $data['df8'];
     $dataPadre->hijos = $data['df79'];
     $dataPadre->familiares_presos = $data['df80'];
     $dataPadre->descripcion_familiares_presos = $data['df81'];
     $dataPadre->id_record = $id;
     $dataPadre->save();
     //Guardar la informacion sobre la madre
     $dataMadre = FamilyData::whereRaw('tipo = ? and id_record = ?', ['madre', $id])->first();
     $dataMadre = $this->familyDataRepo->update($dataMadre, $data);
     $dataMadre->tipo = 'madre';
     $dataMadre->nombre = $data['df9'];
     $dataMadre->edad = $data['df10'];
     $dataMadre->originario = $data['df11'];
     $dataMadre->ingresos = $data['df12'];
     $dataMadre->profecion = $data['df13'];
     $dataMadre->telefono = $data['df14'];
     $dataMadre->direccion = $data['df15'];
     $dataMadre->relacion = $data['df16'];
     $dataMadre->id_record = $id;
     $dataMadre->save();
     //Guardamos la informacion sobre el esposo
     $dataEsposo = FamilyData::whereRaw('tipo = ? and id_record = ?', ['esposo', $id])->first();
     $dataEsposo = $this->familyDataRepo->update($dataEsposo, $data);
     $dataEsposo->tipo = 'esposo';
     $dataEsposo->nombre = $data['df17'];
     $dataEsposo->edad = $data['df18'];
     $dataEsposo->originario = $data['df19'];
     $dataEsposo->ingresos = $data['df20'];
     $dataEsposo->profecion = $data['df21'];
     $dataEsposo->telefono = $data['df22'];
     $dataEsposo->direccion = $data['df23'];
     $dataEsposo->id_record = $id;
     $dataEsposo->save();
     $dataHermano = FamilyData::whereRaw('tipo = ? and id_record = ?', ['hermano', $id])->get();
     $i = 24;
     $indice = 0;
     while ($i < 74) {
         $dataHermano[$indice]->tipo = 'hermano';
         $dataHermano[$indice]->nombre = $data['df' . $i];
         $i++;
         $dataHermano[$indice]->edad = $data['df' . $i];
         $i++;
         $dataHermano[$indice]->profecion = $data['df' . $i];
         $i++;
         $dataHermano[$indice]->telefono = $data['df' . $i];
         $i++;
         $dataHermano[$indice]->observacion = $data['df' . $i];
         $i++;
         $dataHermano[$indice]->id_record = $id;
         $dataHermano[$indice]->save();
         $indice++;
     }
     //Guardamos la informacion del estudiante
     //Educacion Primaria
     $dataEducation = EducationData::whereRaw('tipo = ? and id_record = ?', ['primaria', $id])->first();
     $dataEducation = $this->educationDataRepo->update($dataEducation, $data);
     $dataEducation->establecimiento = $data['de1'];
     $dataEducation->direccion = $data['de2'];
     $dataEducation->fecha = $data['de3'];
     $dataEducation->tipo = 'primaria';
     $dataEducation->id_record = $id;
     $dataEducation->save();
     //Educacion Secundatia
     $dataEducation = EducationData::whereRaw('tipo = ? and id_record = ?', ['secundaria', $id])->first();
     $dataEducation = $this->educationDataRepo->update($dataEducation, $data);
     $dataEducation->establecimiento = $data['de4'];
     $dataEducation->direccion = $data['de5'];
     $dataEducation->fecha = $data['de6'];
     $dataEducation->tipo = 'secundaria';
     $dataEducation->id_record = $id;
     $dataEducation->save();
     //Educacion diversificado
     $dataEducation = EducationData::whereRaw('tipo = ? and id_record = ?', ['diversificado', $id])->first();
     $dataEducation = $this->educationDataRepo->update($dataEducation, $data);
     $dataEducation->establecimiento = $data['de7'];
     $dataEducation->direccion = $data['de8'];
     $dataEducation->fecha = $data['de10'];
     $dataEducation->titulo = $data['de9'];
     $dataEducation->tipo = 'diversificado';
     $dataEducation->id_record = $id;
     $dataEducation->save();
     //Educacion Universidad
     $dataEducation = EducationData::whereRaw('tipo = ? and id_record = ?', ['universidad', $id])->first();
     $dataEducation->establecimiento = $data['de11'];
     $dataEducation->direccion = $data['de12'];
     $dataEducation->fecha = $data['de14'];
     $dataEducation->titulo = $data['de13'];
     $dataEducation->observacion = $data['de15'];
     $dataEducation->tipo = 'universidad';
     $dataEducation->id_record = $id;
     $dataEducation->save();
     //Informacion Laboral
     $dataLabor = LaborData::where('id_record', $id)->get();
     $indice = 0;
     $e = 1;
     while ($e < 231) {
         $dataLabor[$indice]->empresa = $data['dl' . $e++];
         $dataLabor[$indice]->direccion = $data['dl' . $e++];
         $dataLabor[$indice]->telefono = $data['dl' . $e++];
         $dataLabor[$indice]->puesto = $data['dl' . $e++];
         $dataLabor[$indice]->jefe_inmediato = $data['dl' . $e++];
         $dataLabor[$indice]->puesto_jefe_inmediato = $data['dl' . $e++];
         $dataLabor[$indice]->fecha_inicio = $data['dl' . $e++];
         $dataLabor[$indice]->fecha_retiro = $data['dl' . $e++];
         $dataLabor[$indice]->ultimo_salario = $data['dl' . $e++];
         $dataLabor[$indice]->motivo_despido = $data['dl' . $e++];
         $dataLabor[$indice]->departamento_que_confirma = $data['dl' . $e++];
         $dataLabor[$indice]->nombre_puesto = $data['dl' . $e++];
         $dataLabor[$indice]->fechas_en_las_que_laboro = $data['dl' . $e++];
         $dataLabor[$indice]->puesto_que_desempeño = $data['dl' . $e++];
         $dataLabor[$indice]->tiene_llamadas_de_atencion = $data['dl' . $e++];
         $dataLabor[$indice]->motivo_del_retiro = $data['dl' . $e++];
         $dataLabor[$indice]->jefe_inmediato2 = $data['dl' . $e++];
         $dataLabor[$indice]->nombre_y_puesto = $data['dl' . $e++];
         $dataLabor[$indice]->desenpeño = $data['dl' . $e++];
         $dataLabor[$indice]->fortaleza_laborales = $data['dl' . $e++];
         $dataLabor[$indice]->area_de_mejora2 = $data['dl' . $e++];
         $dataLabor[$indice]->como_fueron_sus_relaciones_interpersonales = $data['dl' . $e++];
         $dataLabor[$indice]->motivo_de_retiro2 = $data['dl' . $e++];
         $dataLabor[$indice]->id_record = $id;
         $dataLabor[$indice]->save();
         $indice++;
     }
     // Presupuesto Mensual
     $databudget = BudgetData::where('id_record', $id)->get();
     $indice = 0;
     $i = 1;
     while ($i < 24) {
         $databudget[$indice]->ingresos = $data['ingreso' . $i];
         $databudget[$indice]->egresos = $data['egreso' . $i];
         $databudget[$indice]->diferencia = $data['diferencia' . $i];
         $databudget[$indice]->id_record = $id;
         $databudget[$indice]->save();
         $indice++;
         $i++;
     }
     // Redidencia
     $dataHome = HomeData::where('id_record', $id)->first();
     $dataHome = $this->homeDataRepo->update($dataHome, $data);
     $dataHome->hd1 = $data['hd1'];
     $dataHome->hd2 = $data['hd2'];
     $dataHome->hd3 = $data['hd3'];
     $dataHome->hd4 = $data['hd4'];
     $dataHome->hd5 = $data['hd5'];
     $dataHome->hd6 = $data['hd6'];
     $dataHome->hd7 = $data['hd7'];
     $dataHome->id_record = $id;
     $dataHome->save();
     // Salud
     $dataSalud = SaludData::where('id_record', $id)->first();
     $dataSalud = $this->saludDataRepo->update($dataSalud, $data);
     $dataSalud->sa1 = $data['sa1'];
     $dataSalud->sa2 = $data['sa2'];
     $dataSalud->sa3 = $data['sa3'];
     $dataSalud->sa4 = $data['sa4'];
     $dataSalud->sa5 = $data['sa5'];
     $dataSalud->sa6 = $data['sa6'];
     $dataSalud->sa7 = $data['sa7'];
     $dataSalud->sa8 = $data['sa8'];
     $dataSalud->id_record = $id;
     $dataSalud->save();
     // Vicios
     $dataVicios = ViciosData::where('id_record', $id)->first();
     $dataVicios = $this->viciosDataRepo->update($dataVicios, $data);
     $dataVicios->vi1 = $data['vi1'];
     $dataVicios->vi2 = $data['vi2'];
     $dataVicios->vi3 = $data['vi3'];
     $dataVicios->vi4 = $data['vi4'];
     $dataVicios->vi5 = $data['vi5'];
     $dataVicios->vi6 = $data['vi6'];
     $dataVicios->vi7 = $data['vi7'];
     $dataVicios->vi8 = $data['vi8'];
     $dataVicios->vi9 = $data['vi9'];
     $dataVicios->vi10 = $data['vi10'];
     $dataVicios->vi11 = $data['vi11'];
     $dataVicios->vi12 = $data['vi12'];
     $dataVicios->id_record = $id;
     $dataVicios->save();
     // Vecinos
     $dataVecinos = VecinosData::where('id_record', $id)->get();
     $i = 0;
     $indice = 1;
     while ($indice < 28) {
         $dataVecinos[$i]->v1 = $data['v' . $indice++];
         $dataVecinos[$i]->v2 = $data['v' . $indice++];
         $dataVecinos[$i]->v3 = $data['v' . $indice++];
         $dataVecinos[$i]->v4 = $data['v' . $indice++];
         $dataVecinos[$i]->v5 = $data['v' . $indice++];
         $dataVecinos[$i]->v6 = $data['v' . $indice++];
         $dataVecinos[$i]->v7 = $data['v' . $indice++];
         $dataVecinos[$i]->v8 = $data['v' . $indice++];
         $dataVecinos[$i]->v9 = $data['v' . $indice++];
         $dataVecinos[$i]->id_record = $id;
         $dataVecinos[$i]->save();
         $i++;
     }
     // Generamos el reporte
     $folder = 'pdfs';
     if (!is_dir($folder)) {
         // update directory
         $oldmask = umask(0);
         mkdir($folder, 0777);
         umask($oldmask);
     }
     $ballot_data->url = $folder . '/' . time() . '.pdf';
     $ballot_data->save();
     $pdf_factory = \App::make('dompdf');
     $pdf = $pdf_factory->loadView('pdf', compact('data'))->save($ballot_data->url);
     return ['message' => 'Boleta generada exitosamente', 'success' => true, 'id' => $id];
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOwnerData()
 {
     return $this->hasOne(PersonalData::className(), ['personal_data_id' => 'owner_data_id']);
 }
 public function actionExport($id)
 {
     $templateFilepath = dirname(__FILE__) . '/../runtime/templates/Template2.docx';
     $source = dirname(__FILE__) . '/../runtime/temp.docx';
     \PhpOffice\PhpWord\Autoloader::register();
     $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($templateFilepath);
     $months = ['Січня', 'Лютого', 'Березня', 'Квітня', 'Травня', 'Червня', 'Липня', 'Серпня', 'Вересня', 'Жовтня', 'Листопада', 'Грудня'];
     $date = getdate();
     $currentDate = $date['mday'] . ' ' . $months[$date['mon'] - 1] . ' ' . $date['year'] . ' року';
     $extractNumber = '№' . $date['mday'] . ($date['mon'] - 1) . substr($date['year'], -2);
     $templateProcessor->setValue('date', $currentDate);
     $templateProcessor->setValue('number', $extractNumber);
     $templateProcessor->saveAs($source);
     $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
     //$phpWord = new \PhpOffice\PhpWord\PhpWord();
     $phpWord->setDefaultFontName('Times New Roman');
     $phpWord->setDefaultFontSize(11);
     $sectionStyle = ['marginTop' => 1000];
     $tableStyle = ['borderSize' => 6, 'borderColor' => '000', 'cellMargin' => 0];
     $innerTableStyle = ['cellMargin' => 20];
     $boldFontStyle = ['bold' => true];
     $italicFontStyle = ['italic' => true];
     $styleCell = ['valign' => 'center'];
     $styleCellBTLR = ['valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR];
     $innerTableCellStyle = ['borderRightSize' => 6, 'borderRightColor' => '000', 'borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000'];
     $innerTableRightCellStyle = ['borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000'];
     $innerTableFontStyle = ['size' => 9];
     $innerTableParagraphStyle = ['align' => 'center'];
     // Get resource data
     $resource = Resource::findOne($id);
     $filename = $resource->name . '.docx';
     $coordinates = json_decode($resource->coordinates);
     $owner_name = 'народ України (Український народ)';
     $resource_class = 'природний ресурс';
     $resource_subclass = ResourceClass::findOne($resource->class_id)->name;
     $creation_date = $resource->date;
     $registrar = PersonalData::findOne($resource->registrar_data_id);
     $registrar_info = $registrar->last_name . ' ' . $registrar->first_name . ' ' . $registrar->middle_name . ' ' . $registrar->address;
     $registrar_shortname = $registrar->last_name . $registrar->first_name[0] . '. ' . $registrar->middle_name[0] . '.';
     $parameters = Parameter::find()->where(['resource_id' => $id])->all();
     $attributes = [];
     foreach ($parameters as $parameter) {
         $parameter_name = ResourceAttribute::findOne($parameter->attribute_id);
         $attributes[$parameter_name->name] = $parameter->value;
     }
     $length = $attributes['length'];
     $width = $attributes['width'];
     $height = $attributes['height'];
     if ($length || $width || $height) {
         if (!$length) {
             $length = '0';
         }
         if (!$width) {
             $width = '0';
         }
         if (!$height) {
             $height = '0';
         }
         $attributes['linear_size'] = $length . ':' . $width . ':' . $height;
     }
     $reason = $resource->reason;
     function formatCoords($num)
     {
         $num = round($num, 4, PHP_ROUND_HALF_DOWN);
         $degrees = floor($num);
         $minfloat = ($num - $degrees) * 60;
         $minutes = floor($minfloat);
         $secfloat = ($minfloat - $minutes) * 60;
         $seconds = round($secfloat);
         if ($seconds == 60) {
             $minutes++;
             $seconds = 0;
         }
         if ($minutes == 60) {
             $degrees++;
             $minutes = 0;
         }
         return (string) $degrees . '°' . (string) $minutes . '\'' . (string) $seconds . '"';
     }
     $tableFields = ['Найменування об’єкту' => $resource->name, 'Клас об’єкту' => $resource_class, 'Підклас об’єкту' => $resource_subclass, 'Власник об’єкту' => $owner_name, 'Географічні координати кутів (вершин) об’єкту у форматі ГГ°ММ\'СС,СС". ' => $coordinates, 'Лінійні розміри об’єкту, Д:Ш:В, м' => $attributes['linear_size'], 'Загальна площа об’єкту, га' => $attributes['square'] / 10000, 'Маса (вага) об’єкту, кг' => $attributes['weight'], 'Периметр об’єкту, м' => $attributes['perimeter'], 'Об’єм об’єкту, м3' => $attributes['volume'], 'Підстава для внесення відомостей до Реєстру' => $reason, 'ПІБ та поштова адреса народного реєстратора' => $registrar_info, 'Реєстраційний номер об’єкту' => $registration_number, 'Дата створення запису' => $creation_date];
     $tableUnitalicFields = ['Клас об’єкту', 'Власник об’єкту'];
     $sections = $phpWord->getSections();
     $section = $sections[0];
     $phpWord->addTableStyle('Resource Table', $tableStyle);
     $table = $section->addTable('Resource Table');
     foreach ($tableFields as $key => $value) {
         if ($value) {
             if (!is_array($value)) {
                 $valueFontStyle = [];
                 if (in_array($key, $tableUnitalicFields)) {
                     $valueFontStyle = $italicFontStyle;
                 }
                 $table->addRow(200);
                 $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle);
                 $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(15))->addText(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'), $valueFontStyle);
             } else {
                 $row = $table->addRow();
                 $row->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle);
                 $cell = $row->addCell();
                 $innerTable = $cell->addTable($innerTableStyle);
                 $innerTable->addRow(10);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Північна широта', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Східна довгота', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars("Північна широта \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars("Східна довгота \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle);
                 $coordinatesNumber = count($coordinates);
                 for ($i = 1; $i <= round($coordinatesNumber / 2); $i++) {
                     $lat = '';
                     $lng = '';
                     $latCont = '';
                     $lngCont = '';
                     if ($coordinatesNumber >= $i) {
                         $lat = formatCoords($coordinates[$i - 1][0]);
                         $lng = formatCoords($coordinates[$i - 1][1]);
                     }
                     if ($coordinatesNumber >= round($coordinatesNumber / 2) + $i) {
                         $latCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][0]);
                         $lngCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][1]);
                     }
                     $innerTable->addRow(10);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lat, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lng, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($latCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                     $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars($lngCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle);
                 }
             }
         }
     }
     $section->addTextBreak(2);
     $section->addText('Народний реєстратор', $boldFontStyle);
     $section->addText(htmlspecialchars($registrar_shortname, ENT_COMPAT, 'UTF-8'));
     header("Content-Description: File Transfer");
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
     header('Content-Transfer-Encoding: binary');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Expires: 0');
     $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
     $xmlWriter->save("php://output");
 }